﻿using Module_Debug.Hardware;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.IO.Ports;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using VT_Tool_DLL;

namespace Module_Debug
{
    public partial class VTDR6110 : Form
    {
        //---------------------R66455 the dll function define-----------------------------------
        //De_Mura
        byte[] Erase_Flash_SyR66455_601_SSD =
        {
            0x0d,0x01,0x40,0xc0,0x01,0x00,0xb7,0x07,0x42,0xb1,
            0x01,0x01,0xb2,0x05,0x1b,0xb3,0x44,0x59,0xb4,0x04,
            0x38,0xb5,0x08,0x70,0xb6,0x00,0x37,0xde,0x00,0x03,
            0xb9,0x00,0x00,0xba,0xc2,0x50,0xbb,0x00,0x0c,0xd6,
            0x00,0x05,0xb9,0x00,0x01,0xb8,0x00,0x00,0xc9,0x1b,
            0x09,0xca,0x3a,0x0c,0xcb,0x03,0x1b,0xcc,0x0f,0x14,
            0xdf,0x00,0x3d,0xb7,0x07,0x4b,0xff,0x98,0x21
        };

        byte[] SyR66455_621_DeMura_ON_Part_0 =
        {
            0x30,0x01,0x02,0xb0,0x80,0x8a,0xb3
        };

        byte[] SyR66455_621_DeMura_ON_Part_1 =
        {
            0x30,0x01,0x3c,0xd4,0x93,0x90,0x40,0x1e,0xe1,0x04,
            0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,
            0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,
            0x00,0x04,0x00,0x0f,0xff,0x00,0x00,0x0f,0xff,0x00,
            0x00,0x0f,0xff,0x00,0x00,0x03,0x20,0x00,0xdf,0x00,
            0xc8,0x01,0x00,0x4d,0x8b,0x00,0x4d,0x8b,0x00,0x4d,
            0x8b,0x03,0x38,0xea,0x03
        };

        byte[] SyR66455_621_DeMura_OFF_Part_0 =
{
            0x30,0x01,0x02,0xb0,0x80,0x8a,0xb3
        };

        byte[] SyR66455_621_DeMura_OFF_Part_1 =
        {
            0x30,0x01,0x3c,0xd4,0x90,0x90,0x40,0x1e,0xe1,0x04,
            0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,
            0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,
            0x00,0x04,0x00,0x0f,0xff,0x00,0x00,0x0f,0xff,0x00,
            0x00,0x0f,0xff,0x00,0x00,0x03,0x20,0x00,0xdf,0x00,
            0xc8,0x01,0x00,0x4d,0x8b,0x00,0x4d,0x8b,0x00,0x4d,
            0x8b,0x03,0x38,0x15,0xc0
        };

        byte[] SyR66455_Read_DeMura_Flash_ID_0 =
        {
            0x0d,0x02,0x48,0x02,0xb0,0x00,0x33,0xdf,0x00,0x00,
            0x58,0x83,0x2d,0x05,0x35,0x15,0x01,0x31,0x11,0x0b,
            0x50,0x00,0x02,0x00,0x00,0x43,0x84,0x00,0x10,0x00,
            0xdf,0xd4,0x0e,0x00,0x00,0x13,0xff,0x8c,0x27,0x17,
            0x0f,0x00,0x55,0x18,0x0f,0x00,0x1a,0x0f,0x00,0x1c,
            0x0f,0x00,0x1e,0x0f,0x00,0x00,0x00,0x00,0x06,0xf3,
            0x9f,0x00,0x00,0x00,0x02,0x02,0xf2,0x09,0x02,0x37,
            0x03,0x02,0x14,0xf4,0xff,0xd6,0xbe
        };

        byte[] SyR66455_Read_DeMura_Flash_ID_1 =
        {
            0x30,0x02,0x04,0xf4,0x00,0x00,0x00,0xff,0xb9
        };

        byte[] SyR66455_Read_DeMura_Flash_ID_2 =
        {
            0x0d,0x03,0x03,0xb7,0x07,0x4b,0x2e,0x0a
        };
        byte[] SyR66455_Read_DeMura_Flash_ID_3 =
        {
            0x0a,0x07,0x15,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0xd5,0x70
        };
        byte[] SyR66455_Read_DeMura_Flash_ID_4 =
        {
            0x0d,0x04,0x02,0x14,0xf4,0xf4,0xcb
        };

        byte[] Test1 =
        {
            0x30,0x01,0x02,0xb0,0x00,0x1b,0x3b
        };
        byte[] Test2 =
        {
            0x30,0x01,0x33,0xdf,0x00,0x00,0x58,0x83,0x2d,0x05,
            0x35,0x15,0x01,0x31,0x11,0x0b,0x50,0x00,0x02,0x00,
            0x00,0x43,0x84,0x00,0x10,0x00,0xdf,0xd4,0x0e,0x00,
            0x00,0x13,0xff,0x8c,0x27,0x17,0x0f,0x00,0x55,0x18,
            0x0f,0x00,0x1a,0x0f,0x00,0x1c,0x0f,0x00,0x1e,0x0f,
            0x00,0x00,0x00,0x00,0x82,0xec
        };
        byte[] Test3 =
        {
            0x30,0x01,0x06,0xf3,0x9f,0x00,0x00,0x00,0x02,0x36,
            0xeb
        };
        byte[] Test4 =
        {
            0x30,0x01,0x02,0xf2,0x09,0xe1,0xbc
        };
        byte[] Test5 =
        {
            0x30,0x01,0x02,0x37,0x03,0xa9,0x57
        };
        byte[] Test6 =
        {
            0x30,0x01,0x02,0x14,0xf4,0x65,0x1a
        };
        byte[] Test7 =
        {
            0x30,0x02,0x04,0xf4,0x00,0x00,0x00,0xff,0xb9
        };

        byte[] SyR66455_Read_DeMura_CheckSum_0 =
{
            0x30,0x01,0x02,0xb0,0x00,0x1b,0x3b
        };
        byte[] SyR66455_Read_DeMura_CheckSum_1 =
        {
            0x30,0x01,0x01,0x0b,0x1d,0x43
        };
        byte[] SyR66455_Read_DeMura_CheckSum_2 =
        {
            0x30,0x02,0x04,0xe7,0x00,0x00,0x00,0x7f,0xc2
        };




        byte[] Erase_Flash_SyR66455_601_MIPI =
        {
            0x0d,0x12,0x1c,0x02,0xb0,0x00,0x33,0xdf,0x00,0x40,
            0x58,0x83,0x2d,0x05,0x35,0x15,0x01,0x31,0x11,0x6b,
            0x50,0x00,0x02,0x00,0x00,0x43,0x84,0x00,0x10,0x00,
            0xdf,0xd4,0x0e,0x00,0x00,0x13,0xff,0x8c,0x27,0x17,
            0x0f,0x00,0x55,0x18,0x0f,0x00,0x1a,0x0f,0x00,0x1c,
            0x0f,0x00,0x1e,0x0f,0x00,0x00,0x00,0x00,0x02,0xb0,
            0x00,0x06,0xf3,0x06,0x00,0x00,0x00,0x00,0x04,0xff,
            0xff,0xff,0x0a,0x02,0xf2,0x11,0x02,0xb0,0x00,0x06,
            0xf3,0x05,0x00,0x00,0x00,0x00,0x04,0xff,0xff,0xff,
            0x0a,0x02,0xf2,0x09,0x02,0xb0,0x00,0x02,0x37,0x02,
            0x04,0xff,0xff,0xff,0x0a,0x02,0x14,0xf4,0x04,0xff,
            0xff,0xff,0x0a,0x02,0xb0,0x00,0x06,0xf3,0x60,0x00,
            0x00,0x00,0x00,0x04,0xff,0xff,0xff,0x0a,0x02,0xf2,
            0x11,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
            0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,0xff,0xff,
            0xfa,0x04,0xff,0xff,0xff,0xfa,0xff,0x2b,0xf0,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00
        };
        byte[] Erase_Flash_SyR66455_601_MIPI_1 =
        {
            0x0d,0x02,0x58,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,
            0xff,0xff,0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,
            0xff,0xff,0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,
            0xff,0xff,0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,
            0xff,0xff,0xfa,0x04,0xff,0xff,0xff,0xfa,0x04,0xff,
            0xff,0xff,0xfa,0x02,0xb0,0x00,0x06,0xf3,0x05,0x00,
            0x00,0x00,0x00,0x04,0xff,0xff,0xff,0x0a,0x02,0xf2,
            0x09,0x02,0xb0,0x04,0x02,0x37,0x02,0x04,0xff,0xff,
            0xff,0x0a,0x02,0x14,0xf4,0x04,0xff,0xff,0xff,0x0a,
            0xff,0x07,0x3e
        };
        byte[] SyR66455_601_Send_DeMura_Data_MIPI_Init =//初始化部分
        {
            0x30,0x0f,0x02,0xb0,0x00,0xB9,0x61
        };
        byte[] SyR66455_601_Send_DeMura_Data_MIPI_0 =//初始化部分
        {
            0x30,0x01,0x02,0xb0,0x00,0x1b,0x3b
        };
        byte[] SyR66455_601_Send_DeMura_Data_MIPI_1 =//初始化部分
        {
            0x30,0x01,0x33,0xdf,0x00,0x40,0x58,0x83,0x2d,0x05,
            0x35,0x15,0x01,0x31,0x11,0x6b,0x50,0x00,0x02,0x00,
            0x00,0x43,0x84,0x00,0x10,0x00,0xdf,0xd4,0x0e,0x00,
            0x00,0x13,0xff,0x8c,0x27,0x17,0x0f,0x00,0x55,0x18,
            0x0f,0x00,0x1a,0x0f,0x00,0x1c,0x0f,0x00,0x1e,0x0f,
            0x00,0x00,0x00,0x00,0xa0,0x0c
        };
        byte[] SyR66455_601_Send_DeMura_Data_MIPI_2 =//循环部分
        {
            0x30,0x01,0x02,0xb0,0x04,0x5b,0xbf
        };
        byte[] SyR66455_601_Send_DeMura_Data_MIPI_3 =//循环部分
        {
            0x30,0x01,0x06,0xf3,0x06,0x00,0x00,0x00,0x00,0x98,
            0x5f
        };
        byte[] SyR66455_601_Send_DeMura_Data_MIPI_4 =//循环部分
        {
            0x30,0x01,0x02,0xf2,0x11,0x72,0x85
        };
        byte[] SyR66455_601_Send_DeMura_Data_MIPI_5 =//循环部分_变化_数据地址
        {
            0x30,0x01,0x06,0xf3,0x02,0x00,0x0f,0x00,0x7f,0xb2,
            0x10
        };
        byte[] SyR66455_601_Send_DeMura_Data_MIPI_6 =//循环部分_数据结尾
{
            0x30,0x01,0x02,0xf2,0x1b,0xd3,0xcf
        };


        //De_Mura
        private bool Listening = false;//是否没有执行完invoke相关操作   
        private bool IClosing = false;//是否正在关闭串口，执行Application.DoEvents，并阻止再次invoke  
        //==============ca310===============
        CaSDK Ca310Obj = new CaSDK();
        private double auto_lum;//
        private double auto_x;
        private double auto_y;
        private double auto_T;
        private double auto_duv;
        private bool ca310calFlag = false;
        private int[] tmp_gamma_195 = new int[93];
        private int[] tmp_gamma_160 = new int[33];
        private int[] tmp_gamma_162 = new int[75];
        private int[] tmp_gamma_120 = new int[78];
        private int[] tmp_gamma_010 = new int[75];
        private int[] tmp_gamma_350 = new int[75];
        private int[] tmp_gamma_300 = new int[75];


        /// <summary>
        /// /auto gamma add 20181031
        /// </summary>
        private int flag1 = 1;
        private int flag2 = 1;
        private int flag3 = 1;
        private Boolean flag_R = true;
        private Boolean flag_G = true;
        private Boolean flag_B = true;

        //private ushort[] gamma_r = new ushort[31];
        //private ushort[] gamma_g = new ushort[31];
        //private ushort[] gamma_b = new ushort[31];

        private ushort[] mygamma_r = new ushort[28];
        private ushort[] mygamma_g = new ushort[28];
        private ushort[] mygamma_b = new ushort[28];


        private int step_h = 12;
        private int step_l = 1;
        //==============ca310===============

        private int CAS200_Measure_Gray = 255;
        private int CAS200_Measure_Count = 0;
        private int CA200_Measure_CE = 0;
        private List<byte> buffer = new List<byte>(2048);//默认分配1/16页内存，并始终限制不允许超过   
        private byte[] Rec_tmp = new byte[1];//
        private byte[] Rec_tmp1 = new byte[1];//
        private byte[] Send_buf = new byte[1];
        private byte signal_mode;
        public byte start_trans_flag = 0;
        public byte continueflag = 0;

        public byte VTDR6100_0XFE_XX = 0;
        public byte Seil_port_Find_flag = 0;
        private byte[] Driver_IC = new byte[1];
        private List<string> ImageType;
        private delegate void MonitorSerialPortChangeEventHandler();
        private MonitorSerialPortChangeEventHandler MonitorCom;
        private int serialPortStatus;

        CRC16 CRCData = new CRC16();

        int frm_new_vtdr6110 = 0;
        //public frmStm32updata1(frmMain Frm)
        //{
        //    MainForm = Frm;
        //    InitializeComponent();
        //}

        private static bool Delay(int delayTime)
        {
            DateTime now = DateTime.Now;
            int s;
            do
            {
                TimeSpan spand = DateTime.Now - now;
                s = spand.Seconds;
                Application.DoEvents();
            }
            while (s < delayTime);
            return true;
        }

        frmMain MainForm = null;
        public VTDR6110(frmMain Frm)
        {
            MainForm = Frm;
            InitializeComponent();
            //MainForm.comPort.DataReceived += new SerialDataReceivedEventHandler(SerialPort1_DataReceived);
            string[] s = { ".bmp" };
            this.ImageType = new List<string>(s);
        }


        private void Frm_Activated(object sender, EventArgs e)
        {

        }

        //是否已经绑定了事件        
        private bool IsBindEvent(Type type, Control con, string eventName)
        {
            bool isBind = false;

            PropertyInfo pi = type.GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);   //获取type类定义的所有事件的信息
            EventHandlerList ehl = (EventHandlerList)pi.GetValue(con, null);    //获取con对象的事件处理程序列表
            FieldInfo fieldInfo = (typeof(Control)).GetField("EventText", BindingFlags.Static | BindingFlags.NonPublic); //获取Control类Click事件的字段信息
            Delegate d = ehl[fieldInfo.GetValue(null)];
            if (d == null)
            {
                return isBind;
            }
            foreach (Delegate del in d.GetInvocationList())
            {
                if (del.Method.Name == eventName)
                {
                    isBind = true;
                    break;
                }
            }
            return isBind;
        }
        private void asdftest_dfa(object sender, EventArgs e)
        {
            // bool isBind = IsBindEvent(MainForm.comPort.GetType(), MainForm.comPort, "comboBox_TextChanged");
            //为Button1绑定一个事件处理程序
            Button btn = new Button();
            btn.Click += new
            EventHandler(Frm_Activated);
            //获取Button类定义的所有事件的信息
            PropertyInfo pi =
            (typeof(Button)).GetProperty("Events", BindingFlags.Instance |
            BindingFlags.NonPublic);



        }

        //{
        //    if (!isBind)

        //    {
        //         MainForm.comPort.DataReceived += new SerialDataReceivedEventHandler(SerialPort1_DataReceived);
        //    }
        //}
        //=================================Timer====Start=========================
        private void T1_Tick(object sender, EventArgs e)
        {
            T1.Enabled = false;
            textBox1.Text = textBox1.Text + "通讯故障!\r\n";
            textBox1.Focus();//获取焦点
            textBox1.Select(textBox1.TextLength, 0);//光标定位到文本最后
            textBox1.ScrollToCaret();//滚动到光标处
        }
        private void T2_Tick(object sender, EventArgs e)
        {

            toolStripStatusLabel2.Text = DateTime.Now.ToString();
        }
        //=================================Timer====end=========================
        private void SerialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)//Getting data from Comm Port
        {
            //if (MainForm.IClosing) return;
            try
            {
                Listening = true;//设置标记，说明我已经开始处理数据，一会儿要使用系统UI的。         
                int n = MainForm.comPort.BytesToRead;
                byte[] buf = new byte[n];
                byte data;

                MainForm.comPort.Read(buf, 0, n);//读取缓冲数据     
                bool data_1_catched = false;//缓存记录数据是否捕获到    
                buffer.AddRange(buf);
                byte CRCH, CRCL;
                if (buffer.Count > 3)
                {
                    if (buffer[0] == 0x0B)          //返回 STM32内部 flash 的配置文件数据
                    {
                        if (buffer.Count >= (Int16)(buffer[2] << 8) + (buffer[3]) + 7)
                        {
                            Rec_tmp = new byte[(Int16)(buffer[2] << 8) + (buffer[3]) + 7];
                            byte[] crcTemp = new byte[(Int16)(buffer[2] << 8) + (buffer[3]) + 7];
                            buffer.CopyTo(0, crcTemp, 0, (Int16)(buffer[2] << 8) + (buffer[3]) + 7);

                            CRCData.CalculateCrc16(crcTemp, out CRCH, out CRCL);
                            if (buffer[(Int16)(buffer[2] << 8) + (buffer[3]) + 7 - 2] != CRCH && buffer[(Int16)(buffer[2] << 8) + (buffer[3]) + 7 - 1] != CRCL) //CRC校验出错
                            {
                                buffer.RemoveRange(0, buffer.Count);
                            }
                            else
                            {
                                buffer.CopyTo(0, Rec_tmp, 0, (Int16)(buffer[2] << 8) + (buffer[3]) + 7);//复制一条完整数据到具体的数据缓存   
                                data_1_catched = true;
                                buffer.RemoveRange(0, (Int16)(buffer[2] << 8) + (buffer[3]) + 7);//正确分析一条数据，从缓存中移除数据。
                            }

                        }
                    }
                    else if (buffer[0] == 0xFE)
                    {
                        Rec_tmp = new byte[buffer[2] + 5];
                        byte[] crcTemp = new byte[buffer[2] + 5];
                        buffer.CopyTo(0, crcTemp, 0, buffer[2] + 5);

                        CRCData.CalculateCrc16(crcTemp, out CRCH, out CRCL);
                        if (buffer[buffer[2] + 5 - 2] != CRCH && buffer[buffer[2] + 5 - 1] != CRCL)     //CRC校验出错
                        {
                            buffer.RemoveRange(0, buffer.Count);
                        }
                        else
                        {
                            buffer.CopyTo(0, Rec_tmp, 0, buffer[2] + 5);//复制一条完整数据到具体的数据缓存   
                            data_1_catched = true;
                            buffer.RemoveRange(0, buffer[2] + 5);//正确分析一条数据，从缓存中移除数据。
                            if (Rec_tmp[4] == 0)
                                continueflag = 1;
                        }
                    }
                    else if (buffer[0] == 0x55)     //STM32 更新bin文件成功  返回
                    {
                        if (buffer.Count >= (buffer[2] + 5))
                        {
                            Rec_tmp = new byte[(buffer[2] + 5)];
                            byte[] crcTemp = new byte[(buffer[2] + 5)];
                            buffer.CopyTo(0, crcTemp, 0, (buffer[2] + 5));

                            CRCData.CalculateCrc16(crcTemp, out CRCH, out CRCL);
                            if (buffer[(buffer[2] + 5) - 2] != CRCH && buffer[(buffer[2] + 5) - 1] != CRCL)       //CRC校验出错
                            {
                                buffer.RemoveRange(0, buffer.Count);
                            }
                            else
                            {
                                buffer.CopyTo(0, Rec_tmp, 0, (buffer[2] + 5));//复制一条完整数据到具体的数据缓存   
                                data_1_catched = true;
                                buffer.RemoveRange(0, (buffer[2] + 5));//正确分析一条数据，从缓存中移除数据。
                                switch (Rec_tmp[3])
                                {
                                    case 0x00:
                                        {
                                            start_trans_flag = 1;
                                        }
                                        break;
                                    case 0x01:
                                        {
                                            if (MainForm.comPort.IsOpen == true) MainForm.comPort.Close();
                                        }
                                        break;
                                    case 0x02:
                                        {
                                            start_trans_flag = 0;
                                        }
                                        break;
                                    default:
                                        break;
                                }
                            }

                        }
                    }
                    //RECEIVE
                    // 0x0A: 模组Timing参数 设置  返回
                    // 0x0D: 模组的SSD2828配置数据、DriverIC初始化数据  设置  返回
                    // 0x08: RM67120的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x09: RM67195的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x19: RM67295的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x29: RM67198的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x2E: RM67198的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x0E: RM67160的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x1E: RM67162的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x2A: NT37710的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x2b: HX37710的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x2C: RM69300的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x2D: ICN9608的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x30: R66455 的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x31: TC1100 的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x2F: Demura操作    设置  返回
                    // 0x3C: RM69350的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x4A: CH13721的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x4C: UD61720的Gamma读写、寄存器读写、OTP读写    设置  返回
                    // 0x4D: VTDR6110的Gamma读写、寄存器读写、OTP读写    设置  返回
                    else if (((buffer[0] == 0x1E) || (buffer[0] == 0x0E) || (buffer[0] == 0x0D) || (buffer[0] == 0x0A) || (buffer[0] == 0x09) || (buffer[0] == 0x08) || (buffer[0] == 0x19) || (buffer[0] == 0x29) || (buffer[0] == 0x2A) || (buffer[0] == 0x09) || (buffer[0] == 0x2E) || (buffer[0] == 0x2B) || (buffer[0] == 0x2C) || (buffer[0] == 0x2D) || (buffer[0] == 0x2F) || (buffer[0] == 0x30) || (buffer[0] == 0x31) || (buffer[0] == 0x3C) || (buffer[0] == 0x3D) || (buffer[0] == 0x4A) || (buffer[0] == 0x4C) || (buffer[0] == 0x4D)) && (Setting.TempRecord.cmdLen > 0))
                    {
                        if (buffer.Count >= Setting.TempRecord.cmdLen)
                        {
                            Rec_tmp = new byte[Setting.TempRecord.cmdLen];
                            byte[] crcTemp = new byte[Setting.TempRecord.cmdLen];
                            buffer.CopyTo(0, crcTemp, 0, Setting.TempRecord.cmdLen);

                            CRCData.CalculateCrc16(crcTemp, out CRCH, out CRCL);
                            if (buffer[Setting.TempRecord.cmdLen - 2] != CRCH && buffer[Setting.TempRecord.cmdLen - 1] != CRCL)     //CRC校验出错
                            {
                                buffer.RemoveRange(0, buffer.Count);
                            }
                            else
                            {
                                buffer.CopyTo(0, Rec_tmp, 0, Setting.TempRecord.cmdLen);//复制一条完整数据到具体的数据缓存   
                                data_1_catched = true;
                                buffer.RemoveRange(0, Setting.TempRecord.cmdLen);//正确分析一条数据，从缓存中移除数据。 
                            }
                        }
                    }
                    else
                        buffer.RemoveRange(0, buffer.Count);
                }
                if (data_1_catched)
                {
                    this.Invoke((EventHandler)(delegate
                    {
                        T1.Enabled = false; //停止超时计数

                        //------------------------------------------------------------------------------------------------------------------------
                        if ((Rec_tmp[0] == 0x09) || (Rec_tmp[0] == 0x19) || (Rec_tmp[0] == 0x29) || (Rec_tmp[0] == 0x2e))  //RM67195 & RM67295 & RM67198&RM69298
                        {
                            ;
                        }

                        else if (Rec_tmp[0] == 0x4D)      //VTDR6100
                        {
                            string tmp = "";
                            switch (Rec_tmp[1])
                            {
                                case 0x01:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                            textBox1.Text = textBox1.Text + "写寄存器\tOK！\r\n";
                                    }
                                    break;
                                case 0x02:
                                    {
                                        //if (Setting.TempRecord.VTDR6100CmdType == 0x02)  //register read
                                        {
                                            //string tmp = "";
                                            for (int i = 3; i < (Setting.TempRecord.cmdLen - 3); i++)
                                            {
                                                tmp = tmp + String.Format("{0:X2}", Rec_tmp[i]) + ",";
                                            }
                                            tmp = tmp + String.Format("{0:X2}", Rec_tmp[Setting.TempRecord.cmdLen - 3]);
                                            VTDR6100_txtRegData.Text = tmp;
                                            textBox1.Text = textBox1.Text + "寄存器\t读 OK！\r\n";
                                        }
                                    }
                                    break;
                                case 0x08:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                            textBox1.Text = textBox1.Text + "GAMMA \t写 OK！\r\n";
                                        else if (Rec_tmp[4] == 0x02)
                                            textBox1.Text = textBox1.Text + "GAMMA \t写 ERROR！\r\n";
                                    }
                                    break;
                                case 0x07:
                                    {
                                    }
                                    break;
                                case 0x09:
                                    {
                                        if (Setting.TempRecord.VTDR6100CmdType == 0x03)
                                        {
                                            VTDR6100_R0.Value = Decimal.Parse((Rec_tmp[4] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            VTDR6100_R1.Value = Decimal.Parse((Rec_tmp[6] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            VTDR6100_R3.Value = Decimal.Parse((Rec_tmp[8] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            VTDR6100_R5.Value = Decimal.Parse((Rec_tmp[10] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            VTDR6100_R7.Value = Decimal.Parse((Rec_tmp[12] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            VTDR6100_R11.Value = Decimal.Parse((Rec_tmp[14] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            VTDR6100_R15.Value = Decimal.Parse((Rec_tmp[16] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            VTDR6100_R19.Value = Decimal.Parse((Rec_tmp[18] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());

                                            VTDR6100_R23.Value = Decimal.Parse((Rec_tmp[20] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            VTDR6100_R27.Value = Decimal.Parse((Rec_tmp[22] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            VTDR6100_R31.Value = Decimal.Parse((Rec_tmp[24] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            VTDR6100_R35.Value = Decimal.Parse((Rec_tmp[26] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            VTDR6100_R39.Value = Decimal.Parse((Rec_tmp[28] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            VTDR6100_R47.Value = Decimal.Parse((Rec_tmp[30] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            VTDR6100_R55.Value = Decimal.Parse((Rec_tmp[32] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            VTDR6100_R63.Value = Decimal.Parse((Rec_tmp[34] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());

                                            VTDR6100_R71.Value = Decimal.Parse((Rec_tmp[36] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            VTDR6100_R79.Value = Decimal.Parse((Rec_tmp[38] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            VTDR6100_R95.Value = Decimal.Parse((Rec_tmp[40] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            VTDR6100_R111.Value = Decimal.Parse((Rec_tmp[42] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            VTDR6100_R127.Value = Decimal.Parse((Rec_tmp[44] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            VTDR6100_R159.Value = Decimal.Parse((Rec_tmp[46] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            VTDR6100_R191.Value = Decimal.Parse((Rec_tmp[48] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            VTDR6100_R223.Value = Decimal.Parse((Rec_tmp[50] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());

                                            VTDR6100_R255.Value = Decimal.Parse((Rec_tmp[52] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());

                                            textBox1.Text = textBox1.Text + "红 Gamma数据\t读 OK！\r\n";
                                        }

                                        else if (Setting.TempRecord.VTDR6100CmdType == 0x04)
                                        {
                                            VTDR6100_G0.Value = Decimal.Parse((Rec_tmp[4] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            VTDR6100_G1.Value = Decimal.Parse((Rec_tmp[6] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            VTDR6100_G3.Value = Decimal.Parse((Rec_tmp[8] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            VTDR6100_G5.Value = Decimal.Parse((Rec_tmp[10] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            VTDR6100_G7.Value = Decimal.Parse((Rec_tmp[12] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            VTDR6100_G11.Value = Decimal.Parse((Rec_tmp[14] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            VTDR6100_G15.Value = Decimal.Parse((Rec_tmp[16] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            VTDR6100_G19.Value = Decimal.Parse((Rec_tmp[18] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());

                                            VTDR6100_G23.Value = Decimal.Parse((Rec_tmp[20] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            VTDR6100_G27.Value = Decimal.Parse((Rec_tmp[22] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            VTDR6100_G31.Value = Decimal.Parse((Rec_tmp[24] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            VTDR6100_G35.Value = Decimal.Parse((Rec_tmp[26] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            VTDR6100_G39.Value = Decimal.Parse((Rec_tmp[28] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            VTDR6100_G47.Value = Decimal.Parse((Rec_tmp[30] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            VTDR6100_G55.Value = Decimal.Parse((Rec_tmp[32] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            VTDR6100_G63.Value = Decimal.Parse((Rec_tmp[34] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());

                                            VTDR6100_G71.Value = Decimal.Parse((Rec_tmp[36] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            VTDR6100_G79.Value = Decimal.Parse((Rec_tmp[38] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            VTDR6100_G95.Value = Decimal.Parse((Rec_tmp[40] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            VTDR6100_G111.Value = Decimal.Parse((Rec_tmp[42] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            VTDR6100_G127.Value = Decimal.Parse((Rec_tmp[44] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            VTDR6100_G159.Value = Decimal.Parse((Rec_tmp[46] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            VTDR6100_G191.Value = Decimal.Parse((Rec_tmp[48] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            VTDR6100_G223.Value = Decimal.Parse((Rec_tmp[50] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());

                                            VTDR6100_G255.Value = Decimal.Parse((Rec_tmp[52] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                            textBox1.Text = textBox1.Text + "绿 Gamma数据\t读 OK！\r\n";
                                        }

                                        else if (Setting.TempRecord.VTDR6100CmdType == 0x05)
                                        {
                                            VTDR6100_B0.Value = Decimal.Parse((Rec_tmp[4] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            VTDR6100_B1.Value = Decimal.Parse((Rec_tmp[6] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            VTDR6100_B3.Value = Decimal.Parse((Rec_tmp[8] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            VTDR6100_B5.Value = Decimal.Parse((Rec_tmp[10] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            VTDR6100_B7.Value = Decimal.Parse((Rec_tmp[12] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            VTDR6100_B11.Value = Decimal.Parse((Rec_tmp[14] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            VTDR6100_B15.Value = Decimal.Parse((Rec_tmp[16] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            VTDR6100_B19.Value = Decimal.Parse((Rec_tmp[18] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());

                                            VTDR6100_B23.Value = Decimal.Parse((Rec_tmp[20] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            VTDR6100_B27.Value = Decimal.Parse((Rec_tmp[22] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            VTDR6100_B31.Value = Decimal.Parse((Rec_tmp[24] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            VTDR6100_B35.Value = Decimal.Parse((Rec_tmp[26] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            VTDR6100_B39.Value = Decimal.Parse((Rec_tmp[28] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            VTDR6100_B47.Value = Decimal.Parse((Rec_tmp[30] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            VTDR6100_B55.Value = Decimal.Parse((Rec_tmp[32] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            VTDR6100_B63.Value = Decimal.Parse((Rec_tmp[34] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());

                                            VTDR6100_B71.Value = Decimal.Parse((Rec_tmp[36] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            VTDR6100_B79.Value = Decimal.Parse((Rec_tmp[38] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            VTDR6100_B95.Value = Decimal.Parse((Rec_tmp[40] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            VTDR6100_B111.Value = Decimal.Parse((Rec_tmp[42] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            VTDR6100_B127.Value = Decimal.Parse((Rec_tmp[44] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            VTDR6100_B159.Value = Decimal.Parse((Rec_tmp[46] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            VTDR6100_B191.Value = Decimal.Parse((Rec_tmp[48] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            VTDR6100_B223.Value = Decimal.Parse((Rec_tmp[50] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());

                                            VTDR6100_B255.Value = Decimal.Parse((Rec_tmp[52] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());

                                            textBox1.Text = textBox1.Text + "蓝 Gamma数据\t读 OK！\r\n";
                                        }
                                    }
                                    break;

                                case 0x11:
                                    {
                                        switch (Rec_tmp[3])
                                        {
                                            case 0x01:
                                            case 0x02:
                                            case 0x03:
                                                {
                                                    textBox1.Text = textBox1.Text + "Gamma切换成功！\r\n";
                                                }
                                                break;
                                            default: break;
                                        }
                                        /*if (Rec_tmp[4] == 0x00)
                                        {
                                            textBox1.Text = textBox1.Text + "Gamma切换成功！\r\n";
                                        }*/
                                    }
                                    break;

                                case 0x0D:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            textBox1.Text = textBox1.Text + "OTP Gamma \t写 OK！\r\n";
                                        else if (Rec_tmp[3] == 0x02)
                                            textBox1.Text = textBox1.Text + "OTP Gamma \t写 ERROR！\r\n";
                                    }
                                    break;

                                case 0x0E:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            textBox1.Text = textBox1.Text + "OTP ALL \t写 OK！\r\n";
                                        else if (Rec_tmp[3] == 0x02)
                                            textBox1.Text = textBox1.Text + "OTP ALL \t写 ERROR！\r\n";
                                    }
                                    break;

                                case 0x0F:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            textBox1.Text = textBox1.Text + "OTP Page 0 \t写 OK！\r\n";
                                        else if (Rec_tmp[3] == 0x02)
                                            textBox1.Text = textBox1.Text + "OTP Page 0 \t写 ERROR！\r\n";
                                    }
                                    break;

                                case 0x1A:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            textBox1.Text = textBox1.Text + "OTP Page 4 \t写 OK！\r\n";
                                        else if (Rec_tmp[3] == 0x02)
                                            textBox1.Text = textBox1.Text + "OTP Page 4 \t写 ERROR！\r\n";
                                    }
                                    break;

                                case 0x1B:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            textBox1.Text = textBox1.Text + "OTP Page 1 \t写 OK！\r\n";
                                        else if (Rec_tmp[3] == 0x02)
                                            textBox1.Text = textBox1.Text + "OTP Page 1 \t写 ERROR！\r\n";
                                    }
                                    break;

                                case 0x1C:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            textBox1.Text = textBox1.Text + "OTP Page 2 \t写 OK！\r\n";
                                        else if (Rec_tmp[3] == 0x02)
                                            textBox1.Text = textBox1.Text + "OTP Page 2 \t写 ERROR！\r\n";
                                    }
                                    break;

                                case 0x1D:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            textBox1.Text = textBox1.Text + "OTP Page 5 \t写 OK！\r\n";
                                        else if (Rec_tmp[3] == 0x02)
                                            textBox1.Text = textBox1.Text + "OTP Page 5 \t写 ERROR！\r\n";
                                    }
                                    break;

                                case 0x1E:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            textBox1.Text = textBox1.Text + "OTP Page 7 \t写 OK！\r\n";
                                        else if (Rec_tmp[3] == 0x02)
                                            textBox1.Text = textBox1.Text + "OTP Page 7 \t写 ERROR！\r\n";
                                    }
                                    break;

                                case 0x1F:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            textBox1.Text = textBox1.Text + "Write 2810 \t写 OK！\r\n";
                                        else if (Rec_tmp[3] == 0x02)
                                            textBox1.Text = textBox1.Text + "Write 2810 \t写 ERROR！\r\n";
                                    }
                                    break;

                                case 0x0A:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                            textBox1.Text = textBox1.Text + "GAMMA \t传输 OK！\r\n";
                                        else if (Rec_tmp[4] == 0x02)
                                            textBox1.Text = textBox1.Text + "GAMMA \t传输 ERROR！\r\n";
                                    }
                                    break;
                                case 0x20:
                                    {
                                        //if (Setting.TempRecord.VTDR6100CmdType == 0x02)  //register read
                                        {

                                            for (int i = 3; i < (Setting.TempRecord.cmdLen - 3); i++)
                                            {
                                                tmp = tmp + String.Format("{0:X2}", Rec_tmp[i]) + ",";
                                            }
                                            tmp = tmp + String.Format("{0:X2}", Rec_tmp[Setting.TempRecord.cmdLen - 3]);
                                            textBox1.Text = textBox1.Text + "\n flash ID \r\n" + tmp + "\n flash \t读 完成！\r\n";
                                            //textBox1.Text = "\r\n flash ID\r\n" + textBox1.Text + "\r\n 寄存器\t读 OK！\r\n";
                                        }
                                    }
                                    break;
                                case 0x21:
                                    textBox1.Text = textBox1.Text + "flash 擦除 完成！\r\n";
                                    break;
                                case 0x22:
                                    if ((Rec_tmp[3] == 0x02) && (Rec_tmp[4] == 0x02))
                                    {
                                        textBox1.Text = textBox1.Text + "Flash_enable OK！\r\n";
                                    }
                                    else
                                    {
                                        textBox1.Text = textBox1.Text + "Flash_enable Fail！\r\n";
                                    }
                                    break;
                                case 0x23:
                                    //Setting.TempRecord.cmdLen = 13;////CRC 特殊处理
                                    for (int i = 3; i < (Setting.TempRecord.cmdLen - 3); i++)
                                    {
                                        tmp = tmp + String.Format("{0:X2}", Rec_tmp[i]) + ",";
                                    }
                                    tmp = tmp + String.Format("{0:X2}", Rec_tmp[Setting.TempRecord.cmdLen - 3]);
                                    textBox1.Text = textBox1.Text + tmp + "\n ";

                                    textBox1.Text = textBox1.Text + "Check_Flash 完成！\r\n";
                                    break;
                                case 0x24:
                                    textBox1.Text = textBox1.Text + "\n Step_Five 完成！\r\n";
                                    break;
                                case 0x25:
                                    textBox1.Text = textBox1.Text + "Write_Flash 完成！\r\n";
                                    break;
                                case 0x26:
                                    //Setting.TempRecord.cmdLen = 15;////CRC 特殊处理
                                    for (int i = 3; i < (Setting.TempRecord.cmdLen - 3); i++)
                                    {
                                        tmp = tmp + String.Format("{0:X2}", Rec_tmp[i]) + ",";
                                    }
                                    tmp = tmp + String.Format("{0:X2}", Rec_tmp[Setting.TempRecord.cmdLen - 3]);
                                    textBox1.Text = textBox1.Text + tmp + "\n ";

                                    textBox1.Text = textBox1.Text + "Check_Flash 完成！\r\n";
                                    break;
                                default: break;

                            }
                        }


                        ////---------------------------------------------------Demura----------------------------------------
                        else if (Rec_tmp[0] == 0x2F)  //Demura
                        {
                            if ((Rec_tmp[7] == 0x2E) || (Rec_tmp[7] == 0x3C))   // 297/298/299  //350
                            {
                                if (Rec_tmp[7] == 0x2E)// 297/298/299
                                {
                                    textBox1.Text = textBox1.Text + "297 298 299\r\n";
                                }
                                else if (Rec_tmp[7] == 0x3C) //350
                                {
                                    textBox1.Text = textBox1.Text + "350\r\n";
                                }
                                switch (Rec_tmp[1])
                                {
                                    case 0x01:
                                        {
                                            textBox1.Text = textBox1.Text + "Demura RAM Enable\r\n";
                                        }
                                        break;
                                    case 0x02:
                                        {
                                            textBox1.Text = textBox1.Text + "Demura RAM Disable\r\n";
                                        }
                                        break;
                                    case 0x03:
                                        {
                                            if (Rec_tmp[7] == 0x2E)// 297/298/299
                                            {
                                                if (Rec_tmp[4] == 0x80)
                                                {
                                                    textBox1.Text = textBox1.Text + "Demura RAM write Flash complete ! \r\n";
                                                }
                                            }
                                            else if (Rec_tmp[7] == 0x3C) ///350
                                            {
                                                if (Rec_tmp[4] == 0x08)
                                                {
                                                    textBox1.Text = textBox1.Text + "Demura RAM write Flash1 complete ! \r\n";
                                                }
                                                else if (Rec_tmp[4] == 0x00)
                                                {
                                                    textBox1.Text = textBox1.Text + "ERROR: write Flash1 timeout ! \r\n";
                                                }
                                            }
                                        }
                                        break;
                                    case 0x0A:///350 only
                                        {
                                            if (Rec_tmp[7] == 0x3C) ///350
                                            {
                                                if (Rec_tmp[4] == 0x08)
                                                {
                                                    textBox1.Text = textBox1.Text + "Demura RAM write Flash2 complete ! \r\n";
                                                    MessageBox.Show("载入完成！");
                                                }
                                                else if (Rec_tmp[4] == 0x00)
                                                {
                                                    textBox1.Text = textBox1.Text + "ERROR: write Flash2 timeout ! \r\n";
                                                }
                                            }
                                        }
                                        break;
                                    case 0x04:
                                        {
                                            textBox1.Text = textBox1.Text + "Checksum: " + Rec_tmp[4].ToString("x") + "," + Rec_tmp[5].ToString("x") + "\r\n";
                                        }
                                        break;
                                    case 0x05:
                                        {
                                            if (Rec_tmp[7] == 0x2E)// 297/298/299
                                            {
                                                if (Rec_tmp[4] == 0x80)
                                                {
                                                    textBox1.Text = textBox1.Text + "Flash Erase Success ! \r\n";
                                                }
                                            }
                                            else if (Rec_tmp[7] == 0x3C) ///350
                                            {
                                                if (Rec_tmp[4] == 0x08)
                                                {
                                                    textBox1.Text = textBox1.Text + "Flash Erase Success ! \r\n";
                                                }
                                            }
                                        }
                                        break;
                                    case 0x06:
                                        {
                                            textBox1.Text = textBox1.Text + "flash ID: " + Rec_tmp[4].ToString("x") + "," + Rec_tmp[5].ToString("x") + "," + Rec_tmp[6].ToString("x") + "\r\n";
                                        }
                                        break;
                                    case 0x07:
                                        {
                                            textBox1.Text = textBox1.Text + "Demura function on \r\n";
                                        }
                                        break;
                                    case 0x08:
                                        {
                                            textBox1.Text = textBox1.Text + "Demura function off \r\n";
                                        }
                                        break;
                                    case 0x09:
                                        {
                                            textBox1.Text = textBox1.Text + "Demura OTP complete$ \r\n";
                                        }
                                        break;
                                    default:
                                        break;
                                }
                            }
                        }

                        textBox1.Focus();//获取焦点
                        textBox1.Select(textBox1.TextLength, 0);//光标定位到文本最后
                        textBox1.ScrollToCaret();//滚动到光标处
                        if (textBox1.Lines.Length > 200) textBox1.Text = "";
                    }));
                }
            }
            finally
            {
                Listening = false;

            }

        }


        //=================================LCD cfg function:OLED_Show_Click====Start=================
        private void OLED_Show_Click(object sender, EventArgs e)
        {
            Send_buf = new byte[25];
            Button btnTmp = (Button)sender;
            Setting.TempRecord.cmdLen = 25;
            UInt32 ICS307Temp = 0x00;
            Send_buf[0] = 0x0A; //LCD配置标志
            Send_buf[2] = 0x15; //数据长度
            switch (btnTmp.Name)
            {

                case "btnPatternW":                             //写入Pattern参数
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = byte.Parse(numPatternR.Value.ToString());
                        Send_buf[4] = byte.Parse(numPatternG.Value.ToString());
                        Send_buf[5] = byte.Parse(numPatternB.Value.ToString());
                    }
                    break;
                //case "btnPatternR": Send_buf[1] = 0x08; break; //读取Pattern参数
                //case "btnReload": Send_buf[1] = 0x0A; break; //重新载入图片
                //case "btnPrevPic": Send_buf[1] = 0x0B; break; //上一张图片
                //case "btnNextPic": Send_buf[1] = 0x0C; break; //下一张图片
                //case "mtReadversion": Send_buf[1] = 0x0D; break; //读取程式版本
                case "btnred":
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = 0xFF;
                        Send_buf[4] = 0;
                        Send_buf[5] = 0;
                    }
                    break; //R
                case "btngreen":
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = 0;
                        Send_buf[4] = 0xFF;
                        Send_buf[5] = 0;
                    }
                    break; //G
                case "btnblue":
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = 0;
                        Send_buf[4] = 0;
                        Send_buf[5] = 0xFF;
                    }
                    break; //B
                case "btnwhite":
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = 0xFF;
                        Send_buf[4] = 0xFF;
                        Send_buf[5] = 0xFF;
                    }
                    break; //W
                case "btnblack":
                    {
                        Send_buf[1] = 0x07;
                        Send_buf[3] = 0;
                        Send_buf[4] = 0;
                        Send_buf[5] = 0;
                    }
                    break; //BL
                default:
                    break;
            }

            CRCData.CalculateCrc16(Send_buf, out Send_buf[23], out Send_buf[24]);
            try
            {
                MainForm.comPort.Write(Send_buf, 0, 25);
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
            Thread.Sleep(800);
        }

        private void numPatternR_ValueChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {
                numPatternG.Value = numPatternR.Value;
                numPatternB.Value = numPatternG.Value;
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {
                numPatternG.Value = numPatternR.Value;
                numPatternB.Value = numPatternG.Value;
            }
        }


        //------------------------------------------Demura------------------------------------------------
        private void Demura_Click(object sender, EventArgs e)
        {

            if (MainForm.IC_comboBox.SelectedIndex == 13)  //是新思IC
            {
                Button btnTmp = (Button)sender;
                switch (btnTmp.Name)
                {
                    case "Demura_Function_ON":
                        {
                            try
                            {
                                MainForm.comPort.Write(SyR66455_621_DeMura_ON_Part_0, 0, 7);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                            }

                            T1.Enabled = false;
                            T1.Interval = 50;
                            T1.Enabled = true;
                            try
                            {
                                MainForm.comPort.Write(SyR66455_621_DeMura_ON_Part_1, 0, 65);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                            }

                            T1.Enabled = false;
                            T1.Interval = 100;
                            T1.Enabled = true;
                        }
                        break;
                    case "Demura_Function_OFF":
                        {
                            try
                            {
                                MainForm.comPort.Write(SyR66455_621_DeMura_OFF_Part_0, 0, 7);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                            }

                            T1.Enabled = false;
                            T1.Interval = 50;
                            T1.Enabled = true;
                            try
                            {
                                MainForm.comPort.Write(SyR66455_621_DeMura_OFF_Part_1, 0, 65);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                            }

                            T1.Enabled = false;
                            T1.Interval = 100;
                            T1.Enabled = true;
                        }
                        break;
                    case "Demura_Flash_Enable":
                        {
                            try
                            {
                                Setting.TempRecord.cmdLen = 7;
                                MainForm.comPort.Write(Test1, 0, 7);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                            }


                            try
                            {
                                Setting.TempRecord.cmdLen = 56;
                                MainForm.comPort.Write(Test2, 0, 56);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                            }

                            try
                            {
                                Setting.TempRecord.cmdLen = 11;
                                MainForm.comPort.Write(Test3, 0, 11);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                            }

                            try
                            {
                                Setting.TempRecord.cmdLen = 7;
                                MainForm.comPort.Write(Test4, 0, 7);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                            }

                            try
                            {
                                Setting.TempRecord.cmdLen = 7;
                                MainForm.comPort.Write(Test5, 0, 7);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                            }

                            try
                            {
                                Setting.TempRecord.cmdLen = 7;
                                MainForm.comPort.Write(Test6, 0, 7);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                            }
                            Thread.Sleep(50);

                            try
                            {
                                Setting.TempRecord.cmdLen = 9;
                                MainForm.comPort.Write(Test7, 0, 9);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                            }
                        }
                        break;

                    case "Flash_Check_Demura_data":
                        {
                            //try
                            //{
                            //    Setting.TempRecord.cmdLen = 7;
                            //    MainForm.comPort.Write(SyR66455_Read_DeMura_CheckSum_0, 0, 7);
                            //}
                            //catch
                            //{
                            //    MessageBox.Show("串口有误，请检查", "错误");
                            //}
                            //try
                            //{
                            //    Setting.TempRecord.cmdLen = 6;
                            //    MainForm.comPort.Write(SyR66455_Read_DeMura_CheckSum_1, 0, 6);
                            //}
                            //catch
                            //{
                            //    MessageBox.Show("串口有误，请检查", "错误");
                            //}
                            try
                            {
                                Setting.TempRecord.cmdLen = 9;
                                MainForm.comPort.Write(SyR66455_Read_DeMura_CheckSum_2, 0, 9);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                            }
                        }
                        break;
                    case "Flash_Write_Demura_data":
                        {

                        }
                        break;

                    default: break;
                }
            }
            else//不是新思IC
            {
                //string[] RM67298_Enable_Flash_Control = new string[4] { "fe", "20", "f3", "02"};
                Button btnTmp = (Button)sender;
                Send_buf = new byte[10];
                Setting.TempRecord.cmdLen = 10;
                Send_buf[0] = 0x2F;
                Send_buf[2] = 0x05;
                if (MainForm.IC_comboBox.SelectedIndex == 10)  //if RM297/298/299
                {
                    Send_buf[7] = 0x2E;
                }
                else if (MainForm.IC_comboBox.SelectedIndex == 11)   //if RM350
                {
                    Send_buf[7] = 0x3C;
                }
                switch (btnTmp.Name)
                {
                    case "Demura_Function_ON":
                        {
                            Send_buf[1] = 0x07;
                        }
                        break;
                    case "Demura_Function_OFF":
                        {
                            Send_buf[1] = 0x08;
                        }
                        break;
                    case "Inter_Demura_data":
                        {
                            Send_buf[1] = 0x01;
                        }
                        break;
                    case "Exit_Demura_data":
                        {
                            Send_buf[1] = 0x02;
                        }
                        break;
                    case "Flash_Write_Demura_data":
                        {
                            Send_buf[1] = 0x03;
                        }
                        break;
                    case "Flash_Check_Demura_data":
                        {
                            Send_buf[1] = 0x04;
                        }
                        break;
                    case "Flash_Erase_Demura_data":
                        {
                            Send_buf[1] = 0x05;
                        }
                        break;
                    case "Demura_Flash_Enable":
                        {
                            Send_buf[1] = 0x06;
                        }
                        break;
                    case "Flash_Demura_OTP":
                        {
                            Send_buf[1] = 0x09;
                        }
                        break;
                    case "Flash_Write_Demura_data2":
                        {
                            Send_buf[1] = 0x0A;
                        }
                        break;
                    default:
                        break;
                }
                CRCData.CalculateCrc16(Send_buf, out Send_buf[8], out Send_buf[9]);

                try
                {
                    MainForm.comPort.Write(Send_buf, 0, 10);
                }
                catch
                {
                    MessageBox.Show("串口有误，请检查", "错误");
                }
            }
        }

        //private void btnReload_Demura_File_Click(object sender, EventArgs e)
        //{
        //    FolderBrowserDialog fldb = new FolderBrowserDialog();
        //    fldb.ShowNewFolderButton = false;
        //    DialogResult res = fldb.ShowDialog();
        //    if (res != System.Windows.Forms.DialogResult.OK)
        //    {
        //        MessageBox.Show("没选择任何文件.");
        //        return;
        //    }
        //    string path = fldb.SelectedPath;

        //    if (!Directory.Exists(path))
        //    {
        //        MessageBox.Show("文件夹不存在.");
        //        return;
        //    }
        //    listBox3_Demura_File.Items.Clear();
        //    string s = null;
        //    DirectoryInfo d = new DirectoryInfo(path);
        //    FileInfo[] Files = d.GetFiles("*.hex");

        //    // List<string> lstr = new List<string>();

        //    foreach (FileInfo file in Files)
        //    {
        //        s = file.Name;
        //        listBox3_Demura_File.Items.Add(s);
        //    }

        //    //zangqiang 20180522  增加bin文件 识别
        //    FileInfo[] Files1 = d.GetFiles("*.bin");
        //    foreach (FileInfo file in Files1)
        //    {
        //        s = file.Name;
        //        listBox3_Demura_File.Items.Add(s);
        //    }
        //    //zangqiang 20180522  增加bin文件 识别

        //    textBox5.Text = path;
        //}

        //private void Load_Demura_data_Click(object sender, EventArgs e)
        //{
        //    Int32 m_txlen = 0;
        //    Int32 Once_txlen = 0;
        //    Int32 File_Length, File_Length_tep;
        //    bool tx_en = true;
        //    byte[] TemFileContent = new byte[1024 * 100];
        //    char[] Acsii_array = new char[2];
        //    Int32 div = 0;
        //    div = Convert.ToInt16(MainForm.HACT.Value) * 3;
        //    //div = Convert.ToInt16(LCD_X_SIZE) * 3;
        //    //div = 1080*3;
        //    //div = 255;
        //    System.Int32 ByteReaded = 0x00;
        //    try
        //    {
        //        string FileName = textBox5.Text + '\\' + listBox3_Demura_File.SelectedItem.ToString();
        //        FileStream aFile = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
        //        File_Length = Convert.ToInt32(aFile.Length);
        //        File_Length_tep = File_Length;
        //        while (tx_en)
        //        {
        //            if (File_Length_tep > (File_Length % div))
        //            {
        //                Once_txlen = div;
        //            }
        //            else  //最后一笔
        //            {
        //                Once_txlen = Convert.ToInt32(aFile.Length % div);
        //                tx_en = false;
        //            }
        //            aFile.Seek(0 + m_txlen, SeekOrigin.Begin);    //跳转
        //            ByteReaded = aFile.Read(TemFileContent, 5, Once_txlen); // 存入第五位
        //            try
        //            {
        //                TemFileContent[0] = 0x5B;
        //                TemFileContent[1] = Convert.ToByte(File_Length >> 24);
        //                TemFileContent[2] = Convert.ToByte((File_Length >> 16) & 0xff);
        //                TemFileContent[3] = Convert.ToByte((File_Length >> 8) & 0xff);
        //                TemFileContent[4] = Convert.ToByte(File_Length & 0xff);
        //                MainForm.comPort.Write(TemFileContent, 0, ByteReaded + 5);
        //            }
        //            catch
        //            {
        //                MessageBox.Show("串口有误，请检查", "错误");
        //                tx_en = false;
        //                break;
        //            }
        //            //tx_en = false;
        //            m_txlen += ByteReaded;
        //            progressBar2.Value = Convert.ToInt32((double)m_txlen / File_Length * 100);
        //            label_flash.Text = progressBar2.Value.ToString() + "%";
        //            Application.DoEvents();//重点，必须加上，否则父子窗体都假死
        //            File_Length_tep = File_Length_tep - div;
        //        }
        //        Demura_Click(Flash_Write_Demura_data, null);

        //        //------------------------------载入第二笔数据-----------------------
        //        if (MainForm.IC_comboBox.SelectedIndex == Setting.IC_Type.RM69350) //瑞鼎（69350）
        //        {
        //            Int32 RM6935x_Demura_part2_addr = 0x180000; //第二笔补偿数据起始地址
        //            Int32 RM6935x_Demura_part2_length = (File_Length - 0x180000) + (0xF - (File_Length - 0x180000) % 0x10); //0x12310F;//第二笔补偿数据总长，256取整
        //            File_Length_tep = RM6935x_Demura_part2_length;
        //            File_Length = RM6935x_Demura_part2_length;
        //            tx_en = true;
        //            m_txlen = 0;
        //            while (tx_en)
        //            {
        //                if (File_Length_tep > (File_Length % div))
        //                {
        //                    Once_txlen = div;
        //                }
        //                else  //最后一笔
        //                {
        //                    Once_txlen = Convert.ToInt32(File_Length % div);
        //                    tx_en = false;
        //                }
        //                aFile.Seek(RM6935x_Demura_part2_addr + m_txlen, SeekOrigin.Begin);    //跳转
        //                ByteReaded = aFile.Read(TemFileContent, 5, Once_txlen); // 存入第五位
        //                try
        //                {
        //                    TemFileContent[0] = 0x5B;
        //                    TemFileContent[1] = Convert.ToByte(File_Length >> 24);
        //                    TemFileContent[2] = Convert.ToByte((File_Length >> 16) & 0xff);
        //                    TemFileContent[3] = Convert.ToByte((File_Length >> 8) & 0xff);
        //                    TemFileContent[4] = Convert.ToByte(File_Length & 0xff);
        //                    MainForm.comPort.Write(TemFileContent, 0, Once_txlen + 5);
        //                }
        //                catch
        //                {
        //                    MessageBox.Show("串口有误，请检查", "错误");
        //                    tx_en = false;
        //                    break;
        //                }
        //                //tx_en = false;
        //                m_txlen += ByteReaded;
        //                progressBar2.Value = Convert.ToInt32((double)m_txlen / File_Length * 100);
        //                label_flash.Text = progressBar2.Value.ToString() + "%";
        //                Application.DoEvents();
        //                File_Length_tep = File_Length_tep - div;
        //            }
        //            Demura_Click(Flash_Write_Demura_data2, null);
        //        }
        //        else
        //        {
        //            MessageBox.Show("载入完成！");
        //        }
        //        aFile.Close();
        //    }
        //    catch
        //    {
        //        MessageBox.Show("请选择文件夹", "错误");
        //    }

        //}


        private void CAS200_Measure_Information(double Dgv_lum, double Dgv_x, double Dgv_y)
        {
            int Row_Accum = 0, Current_Index = 0, Row_flag = 0;

            DataGridViewRow Row1 = new DataGridViewRow();
            Row_Accum = this.CAS200_dataGridView.Rows.Count - 1;
            if (Row_Accum != 0)
            {
                Current_Index = this.CAS200_dataGridView.SelectedCells[0].RowIndex;
                if ((Current_Index != Row_Accum - 1) && (Current_Index != Row_Accum))
                {
                    Row_Accum = Current_Index;
                    Row_flag = 1;
                }
                else
                {
                    this.CAS200_dataGridView.Rows.Add(Row1);
                }
                if ((Row_Accum != 0) && (Row_flag != 1))
                {
                    if (Current_Index != Row_Accum)
                    {
                        this.CAS200_dataGridView.Rows[Row_Accum - 1].Selected = false;
                        this.CAS200_dataGridView.Rows[Row_Accum].Selected = true;
                    }
                }
            }
            else
            {
                this.CAS200_dataGridView.Rows.Add(Row1);
            }
            this.CAS200_dataGridView.Rows[Row_Accum].Cells[0].Value = Row_Accum + 1;//序号
            //Rows[x]为第x行,Cells[x]为第x列
            this.CAS200_dataGridView.Rows[Row_Accum].Cells[1].Value = Dgv_x.ToString("#0.0000");
            this.CAS200_dataGridView.Rows[Row_Accum].Cells[2].Value = Dgv_y.ToString("#0.0000");
            this.CAS200_dataGridView.Rows[Row_Accum].Cells[3].Value = Dgv_lum.ToString("#0.0000");
            if (Row_flag == 1)
            {
                Row_flag = 0;
                Row_Accum = this.CAS200_dataGridView.Rows.Count - 1;
                this.CAS200_dataGridView.Rows[Current_Index].Selected = false;
                this.CAS200_dataGridView.Rows[Row_Accum - 1].Selected = true;
            }
            CAS200_dataGridView.FirstDisplayedScrollingRowIndex = CAS200_dataGridView.RowCount - 1;
        }
        private void Pattern_Write(byte R_value, byte G_value, byte B_value)
        {
            numPatternR.Value = R_value;
            numPatternG.Value = G_value;
            numPatternB.Value = B_value;
            OLED_Show_Click(btnPatternW, null);
        }
        private void T3_Tick(object sender, EventArgs e)
        {
            //    if (check_follow_CE_Auto_measure.Checked == true)
            //    {
            //        string strLine = Convert.ToString(text_CE_data.Text);
            //        string[] arr = strLine.Split(','); //以逗号分割，添加到数组              
            //        if ((MainForm.IC_comboBox.SelectedIndex == 0) || (MainForm.IC_comboBox.SelectedIndex == 4) || (MainForm.IC_comboBox.SelectedIndex == 5) || (MainForm.IC_comboBox.SelectedIndex == 10)) //rm67195
            //        {
            //            txtRM67195Add.Text = arr[0];
            //            txtRM67195Data.Text = CA200_Measure_CE.ToString("x");
            //            RM196_Others_Click(RM67195_RegW, e);
            //            Thread.Sleep(20);
            //        }
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 6) //NT37710
            //        //{
            //        //    /*
            //        //    Setting.TempRecord.cmdLen = arr.Length + 5;
            //        //    Send_buf = new byte[arr.Length + 5];
            //        //    Send_buf[0] = 0x2A;
            //        //    Send_buf[1] = 0x01;
            //        //    Send_buf[2] = byte.Parse(arr.Length.ToString());
            //        //    for (int i = 0; i < arr.Length-1; i++)
            //        //    {
            //        //        Send_buf[3 + i] = byte.Parse((Convert.ToInt32(arr[i], 16)).ToString());
            //        //    }
            //        //    arr[arr.Length - 1] = CA200_Measure_CE.ToString("x");
            //        //    CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + arr.Length - 2], out Send_buf[5 + arr.Length - 1]);
            //        //    try
            //        //    {
            //        //        comPort.Write(Send_buf, 0, 5 + arr.Length);
            //        //    }
            //        //    catch
            //        //    {
            //        //        MessageBox.Show("串口有误，请检查", "错误");
            //        //    } */
            //        //    NT37710_txtRegData.Text = "";
            //        //    for (int i = 0; i < arr.Length - 1; i++)
            //        //    {
            //        //        NT37710_txtRegData.Text += arr[i].ToString() + ",";
            //        //    }
            //        //    NT37710_txtRegData.Text += CA200_Measure_CE.ToString("x");
            //        //    NT37710_RegWR_Click(NT37710_RegW, e);
            //        //    // T1.Enabled = false;
            //        //    // T1.Interval = 2000;
            //        //    //T1.Enabled = true;
            //        //    Thread.Sleep(20);
            //        //}
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 8)//69300
            //        //{
            //        //    RM69300_Reg_Addr.Text = arr[0];
            //        //    RM69300_Reg_Data.Text = CA200_Measure_CE.ToString("x");
            //        //    RM300_Others_Click(RM69300_Reg_W, e);
            //        //    Thread.Sleep(20);
            //        //}
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 9)//ICN9608
            //        //{
            //        //    ICN9608_txtRegData.Text = text_CE_data.Text;
            //        //    ICN9608_RegWR_Click(ICN9608_RegW, e);
            //        //    Thread.Sleep(20);
            //        //}
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 11)//69350
            //        //{
            //        //    R69350_Reg_Addr.Text = arr[0];
            //        //    R69350_Reg_Data.Text = CA200_Measure_CE.ToString("x");
            //        //    RM350_Others_Click(RM69350_Reg_W, e);
            //        //    Thread.Sleep(20);
            //        //}
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 15)//CH13721
            //        //{
            //        //    CH13721_txtRegData.Text = text_CE_data.Text;
            //        //    CH13721_RegWR_Click(CH13721_RegW, e);
            //        //    Thread.Sleep(20);
            //        //}
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 16)//UD61720
            //        //{
            //        //    UD61720_txtRegData.Text = text_CE_data.Text;
            //        //    UD61720_RegWR_Click(UD61720_RegW, e);
            //        //    Thread.Sleep(20);
            //        //}
            //        CA200_Measure_CE = CA200_Measure_CE + int.Parse(CAS200_txt0.Text);

            //        if (CA200_Measure_CE > (byte.Parse((Convert.ToInt32(arr[arr.Length - 1], 16).ToString())) + Convert.ToInt32(text_CE_times.Text) - 1))
            //            T3.Enabled = false;
            //    }

            //    else if (cbx_follow_51_points.Checked == true)
            //    {
            //        if ((MainForm.IC_comboBox.SelectedIndex == 0) || (MainForm.IC_comboBox.SelectedIndex == 4) || (MainForm.IC_comboBox.SelectedIndex == 5) || (MainForm.IC_comboBox.SelectedIndex == 10)) //rm67195
            //        {
            //            txtRM67195Add.Text = "FE";
            //            txtRM67195Data.Text = "00";
            //            RM196_Others_Click(RM67195_RegW, e);

            //            txtRM67195Add.Text = "51";
            //            txtRM67195Data.Text = CAS200_Measure_Gray.ToString("x");
            //            RM196_Others_Click(RM67195_RegW, e);
            //        }
            //        //if (MainForm.IC_comboBox.SelectedIndex == 7) //HX83200
            //        //{
            //        //    txtHX83200Add.Text = "FE";
            //        //    txtHX83200Data.Text = "00";
            //        //    HX83200_RegWR_Click(HX83200_RegW, e);

            //        //    txtHX83200Add.Text = "51";
            //        //    txtHX83200Data.Text = CAS200_Measure_Gray.ToString("x");
            //        //    HX83200_RegWR_Click(HX83200_RegW, e);
            //        //}

            //        //else if ((MainForm.IC_comboBox.SelectedIndex == 2) || (MainForm.IC_comboBox.SelectedIndex == 3)) //rm67160/62
            //        //{
            //        //    txtRM67160Add.Text = "FE";
            //        //    txtRM67160Data.Text = "00";
            //        //    btnModeSet_Click(btnRegW, e);

            //        //    txtRM67160Add.Text = "51";
            //        //    CAS200_Measure_Gray.ToString("x");
            //        //    btnModeSet_Click(btnRegW, e);
            //        //}
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 8)//69300
            //        //{
            //        //    RM69300_Reg_Addr.Text = "FE";
            //        //    RM69300_Reg_Data.Text = "00";
            //        //    RM300_Others_Click(RM69300_51Reg_W, e);

            //        //    RM69300_Reg_Addr.Text = "51";
            //        //    RM69300_Reg_Data.Text = CAS200_Measure_Gray.ToString("x");
            //        //    RM300_Others_Click(RM69300_51Reg_W, e);
            //        //}
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 9)//ICN9608
            //        //{
            //        //    ICN9608_txtRegData.Text = "51," + CAS200_Measure_Gray.ToString("x");
            //        //    ICN9608_RegWR_Click(ICN9608_51RegW, e);
            //        //    Thread.Sleep(20);
            //        //}
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 15)//CH13721
            //        //{
            //        //    CH13721_txtRegData.Text = "51," + CAS200_Measure_Gray.ToString("x");
            //        //    CH13721_RegWR_Click(CH13721_51Reg_W, e);
            //        //    Thread.Sleep(20);
            //        //}
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 16)//UD61720
            //        //{
            //        //    UD61720_txtRegData.Text = "51," + CAS200_Measure_Gray.ToString("x");
            //        //    UD61720_RegWR_Click(UD61720_51Reg_W, e);
            //        //    Thread.Sleep(20);
            //        //}
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 11)//69350
            //        //{
            //        //    R69350_Reg_Addr.Text = "FE";
            //        //    R69350_Reg_Data.Text = "00";
            //        //    RM350_Others_Click(RM69350_51Reg_W, e);

            //        //    R69350_Reg_Addr.Text = "51";
            //        //    R69350_Reg_Data.Text = CAS200_Measure_Gray.ToString("x");
            //        //    RM350_Others_Click(RM69350_51Reg_W, e);
            //        //}
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 13)//66455
            //        //{
            //        //    int R66455_51h_register = 0;
            //        //    R66455_51h_register = Convert.ToInt32(4095 - (float)((float)((float)(255 - CAS200_Measure_Gray) / 255) * 4095));
            //        //    R66455_txtRegData.Text = "51," + R66455_51h_register.ToString("x4").Substring(0, 2) + "," + R66455_51h_register.ToString("x4").Substring(2, 2);
            //        //    R66455_GammaW_Click(R66455_RegW, e);
            //        //    Thread.Sleep(20);
            //        //}
            //        CAS200_Measure_Gray = CAS200_Measure_Gray - Convert.ToInt32(CAS200_txt0.Text);
            //        if (CAS200_Measure_Gray < 0)
            //            T3.Enabled = false;
            //    }
            //    else if (cbx_follow_gamma_points.Checked == true)  //follow gamma绑点
            //    {
            //        CAS200_Measure_Count++; //跳阶
            //        if ((MainForm.IC_comboBox.SelectedIndex == 0) || (MainForm.IC_comboBox.SelectedIndex == 4) || (MainForm.IC_comboBox.SelectedIndex == 5) || (MainForm.IC_comboBox.SelectedIndex == 10)) //rm67195
            //        {
            //            if (CAS200_Measure_Count < Parttern_RM67195.Length)
            //            {
            //                if (numPatternR.Value * numPatternG.Value * numPatternB.Value == 0)
            //                {
            //                    if (numPatternR.Value != 0)
            //                    {
            //                        numPatternR.Value = Parttern_RM67195[CAS200_Measure_Count];
            //                    }
            //                    if (numPatternG.Value != 0)
            //                    {
            //                        numPatternG.Value = Parttern_RM67195[CAS200_Measure_Count];
            //                    }
            //                    if (numPatternB.Value != 0)
            //                    {
            //                        numPatternB.Value = Parttern_RM67195[CAS200_Measure_Count];
            //                    }
            //                }
            //                else
            //                {
            //                    numPatternB.Value = numPatternG.Value = numPatternR.Value = Parttern_RM67195[CAS200_Measure_Count];
            //                }
            //                Pattern_Write((byte)(numPatternR.Value), (byte)(numPatternG.Value), (byte)(numPatternB.Value));
            //            }
            //            else
            //            {
            //                CAS200_Measure_Count = 0;
            //                T3.Enabled = false;
            //            }
            //        }
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 9)  //ICN9608
            //        //{
            //        //    if (CAS200_Measure_Count < Parttern_ICN9608.Length)
            //        //    {
            //        //        if (numPatternR.Value * numPatternG.Value * numPatternB.Value == 0)
            //        //        {
            //        //            if (numPatternR.Value != 0)
            //        //            {
            //        //                numPatternR.Value = Parttern_ICN9608[CAS200_Measure_Count];
            //        //            }
            //        //            if (numPatternG.Value != 0)
            //        //            {
            //        //                numPatternG.Value = Parttern_ICN9608[CAS200_Measure_Count];
            //        //            }
            //        //            if (numPatternB.Value != 0)
            //        //            {
            //        //                numPatternB.Value = Parttern_ICN9608[CAS200_Measure_Count];
            //        //            }
            //        //        }
            //        //        else
            //        //        {
            //        //            numPatternB.Value = numPatternG.Value = numPatternR.Value = Parttern_ICN9608[CAS200_Measure_Count];
            //        //        }
            //        //        Pattern_Write((byte)(numPatternR.Value), (byte)(numPatternG.Value), (byte)(numPatternB.Value));
            //        //    }
            //        //    else
            //        //    {
            //        //        CAS200_Measure_Count = 0;
            //        //        T3.Enabled = false;
            //        //    }
            //        //}
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 16)  //UD61720
            //        //{
            //        //    if (CAS200_Measure_Count < Parttern_UD61720.Length)
            //        //    {
            //        //        if (numPatternR.Value * numPatternG.Value * numPatternB.Value == 0)
            //        //        {
            //        //            if (numPatternR.Value != 0)
            //        //            {
            //        //                numPatternR.Value = Parttern_UD61720[CAS200_Measure_Count];
            //        //            }
            //        //            if (numPatternG.Value != 0)
            //        //            {
            //        //                numPatternG.Value = Parttern_UD61720[CAS200_Measure_Count];
            //        //            }
            //        //            if (numPatternB.Value != 0)
            //        //            {
            //        //                numPatternB.Value = Parttern_UD61720[CAS200_Measure_Count];
            //        //            }
            //        //        }
            //        //        else
            //        //        {
            //        //            numPatternB.Value = numPatternG.Value = numPatternR.Value = Parttern_UD61720[CAS200_Measure_Count];
            //        //        }
            //        //        Pattern_Write((byte)(numPatternR.Value), (byte)(numPatternG.Value), (byte)(numPatternB.Value));
            //        //    }
            //        //    else
            //        //    {
            //        //        CAS200_Measure_Count = 0;
            //        //        T3.Enabled = false;
            //        //    }
            //        //}
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 15)  //CH13721
            //        //{
            //        //    if (CAS200_Measure_Count < Parttern_CH13721.Length)
            //        //    {
            //        //        if (numPatternR.Value * numPatternG.Value * numPatternB.Value == 0)
            //        //        {
            //        //            if (numPatternR.Value != 0)
            //        //            {
            //        //                numPatternR.Value = Parttern_CH13721[CAS200_Measure_Count];
            //        //            }
            //        //            if (numPatternG.Value != 0)
            //        //            {
            //        //                numPatternG.Value = Parttern_CH13721[CAS200_Measure_Count];
            //        //            }
            //        //            if (numPatternB.Value != 0)
            //        //            {
            //        //                numPatternB.Value = Parttern_CH13721[CAS200_Measure_Count];
            //        //            }
            //        //        }
            //        //        else
            //        //        {
            //        //            numPatternB.Value = numPatternG.Value = numPatternR.Value = Parttern_CH13721[CAS200_Measure_Count];
            //        //        }
            //        //        Pattern_Write((byte)(numPatternR.Value), (byte)(numPatternG.Value), (byte)(numPatternB.Value));
            //        //    }
            //        //    else
            //        //    {
            //        //        CAS200_Measure_Count = 0;
            //        //        T3.Enabled = false;
            //        //    }
            //        //}
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 8)  //rm69300
            //        //{
            //        //    if (CAS200_Measure_Count < Parttern_RM67300.Length)
            //        //    {
            //        //        if (numPatternR.Value * numPatternG.Value * numPatternB.Value == 0)
            //        //        {
            //        //            if (numPatternR.Value != 0)
            //        //            {
            //        //                numPatternR.Value = Parttern_RM67300[CAS200_Measure_Count];
            //        //            }
            //        //            if (numPatternG.Value != 0)
            //        //            {
            //        //                numPatternG.Value = Parttern_RM67300[CAS200_Measure_Count];
            //        //            }
            //        //            if (numPatternB.Value != 0)
            //        //            {
            //        //                numPatternB.Value = Parttern_RM67300[CAS200_Measure_Count];
            //        //            }
            //        //        }

            //        //        else
            //        //        {
            //        //            numPatternB.Value = numPatternG.Value = numPatternR.Value = Parttern_RM67300[CAS200_Measure_Count];
            //        //        }
            //        //        Pattern_Write((byte)(numPatternR.Value), (byte)(numPatternG.Value), (byte)(numPatternB.Value));
            //        //    }
            //        //    else
            //        //    {
            //        //        CAS200_Measure_Count = 0;
            //        //        T3.Enabled = false;
            //        //    }
            //        //}
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 11)  //rm69350
            //        //{
            //        //    if (CAS200_Measure_Count < Parttern_RM67350.Length)
            //        //    {
            //        //        if (numPatternR.Value * numPatternG.Value * numPatternB.Value == 0)
            //        //        {
            //        //            if (numPatternR.Value != 0)
            //        //            {
            //        //                numPatternR.Value = Parttern_RM67350[CAS200_Measure_Count];
            //        //            }
            //        //            if (numPatternG.Value != 0)
            //        //            {
            //        //                numPatternG.Value = Parttern_RM67350[CAS200_Measure_Count];
            //        //            }
            //        //            if (numPatternB.Value != 0)
            //        //            {
            //        //                numPatternB.Value = Parttern_RM67350[CAS200_Measure_Count];
            //        //            }
            //        //        }

            //        //        else
            //        //        {
            //        //            numPatternB.Value = numPatternG.Value = numPatternR.Value = Parttern_RM67350[CAS200_Measure_Count];
            //        //        }
            //        //        Pattern_Write((byte)(numPatternR.Value), (byte)(numPatternG.Value), (byte)(numPatternB.Value));
            //        //    }
            //        //    else
            //        //    {
            //        //        CAS200_Measure_Count = 0;
            //        //        T3.Enabled = false;
            //        //    }
            //        //}
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 1) //rm67120
            //        //{
            //        //    if (CAS200_Measure_Count < Parttern_RM67120.Length)
            //        //    {
            //        //        if (numPatternR.Value * numPatternG.Value * numPatternB.Value == 0)
            //        //        {
            //        //            if (numPatternR.Value != 0)
            //        //            {
            //        //                numPatternR.Value = Parttern_RM67120[CAS200_Measure_Count];
            //        //            }
            //        //            if (numPatternG.Value != 0)
            //        //            {
            //        //                numPatternG.Value = Parttern_RM67120[CAS200_Measure_Count];
            //        //            }
            //        //            if (numPatternB.Value != 0)
            //        //            {
            //        //                numPatternB.Value = Parttern_RM67120[CAS200_Measure_Count];
            //        //            }
            //        //        }
            //        //        else
            //        //        {
            //        //            numPatternB.Value = numPatternG.Value = numPatternR.Value = Parttern_RM67120[CAS200_Measure_Count];
            //        //        }
            //        //        Pattern_Write((byte)(numPatternR.Value), (byte)(numPatternG.Value), (byte)(numPatternB.Value));
            //        //    }
            //        //    else
            //        //    {
            //        //        CAS200_Measure_Count = 0;
            //        //        T3.Enabled = false;
            //        //    }
            //        //}
            //        //else if ((MainForm.IC_comboBox.SelectedIndex == 2) || (MainForm.IC_comboBox.SelectedIndex == 3)) //rm67160/62
            //        //{
            //        //    if (CAS200_Measure_Count < Parttern_RM67162.Length)
            //        //    {
            //        //        if (numPatternR.Value * numPatternG.Value * numPatternB.Value == 0)
            //        //        {
            //        //            if (numPatternR.Value != 0)
            //        //            {
            //        //                numPatternR.Value = Parttern_RM67162[CAS200_Measure_Count];
            //        //            }
            //        //            if (numPatternG.Value != 0)
            //        //            {
            //        //                numPatternG.Value = Parttern_RM67162[CAS200_Measure_Count];
            //        //            }
            //        //            if (numPatternB.Value != 0)
            //        //            {
            //        //                numPatternB.Value = Parttern_RM67162[CAS200_Measure_Count];
            //        //            }
            //        //        }
            //        //        else
            //        //        {
            //        //            numPatternB.Value = numPatternG.Value = numPatternR.Value = Parttern_RM67162[CAS200_Measure_Count];
            //        //        }
            //        //        Pattern_Write((byte)(numPatternR.Value), (byte)(numPatternG.Value), (byte)(numPatternB.Value));
            //        //    }
            //        //    else
            //        //    {
            //        //        CAS200_Measure_Count = 0;
            //        //        T3.Enabled = false;
            //        //    }
            //        //}
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 7) //HX83200
            //        //{
            //        //    if (CAS200_Measure_Count < Parttern_RM67162.Length)
            //        //    {
            //        //        if (numPatternR.Value * numPatternG.Value * numPatternB.Value == 0)
            //        //        {
            //        //            if (numPatternR.Value != 0)
            //        //            {
            //        //                numPatternR.Value = Parttern_RM67162[CAS200_Measure_Count];
            //        //            }
            //        //            if (numPatternG.Value != 0)
            //        //            {
            //        //                numPatternG.Value = Parttern_RM67162[CAS200_Measure_Count];
            //        //            }
            //        //            if (numPatternB.Value != 0)
            //        //            {
            //        //                numPatternB.Value = Parttern_RM67162[CAS200_Measure_Count];
            //        //            }
            //        //        }
            //        //        else
            //        //        {
            //        //            numPatternB.Value = numPatternG.Value = numPatternR.Value = Parttern_RM67162[CAS200_Measure_Count];
            //        //        }
            //        //        Pattern_Write((byte)(numPatternR.Value), (byte)(numPatternG.Value), (byte)(numPatternB.Value));
            //        //    }
            //        //    else
            //        //    {
            //        //        CAS200_Measure_Count = 0;
            //        //        T3.Enabled = false;
            //        //    }
            //        //}
            //        //else if (MainForm.IC_comboBox.SelectedIndex == 13) //R66455
            //        //{
            //        //    if (CAS200_Measure_Count < Parttern_R66455.Length)
            //        //    {
            //        //        if (numPatternR.Value * numPatternG.Value * numPatternB.Value == 0)
            //        //        {
            //        //            if (numPatternR.Value != 0)
            //        //            {
            //        //                numPatternR.Value = Parttern_R66455[CAS200_Measure_Count];
            //        //            }
            //        //            if (numPatternG.Value != 0)
            //        //            {
            //        //                numPatternG.Value = Parttern_R66455[CAS200_Measure_Count];
            //        //            }
            //        //            if (numPatternB.Value != 0)
            //        //            {
            //        //                numPatternB.Value = Parttern_R66455[CAS200_Measure_Count];
            //        //            }
            //        //        }
            //        //        else
            //        //        {
            //        //            numPatternB.Value = numPatternG.Value = numPatternR.Value = Parttern_R66455[CAS200_Measure_Count];
            //        //        }
            //        //        Pattern_Write((byte)(numPatternR.Value), (byte)(numPatternG.Value), (byte)(numPatternB.Value));
            //        //    }
            //        //    else
            //        //    {
            //        //        CAS200_Measure_Count = 0;
            //        //        T3.Enabled = false;
            //        //    }
            //        //}
            //    }
            //    else
            //    {
            //        if ((Convert.ToInt16(numPatternR.Value.ToString()) + Convert.ToInt16(numPatternB.Value.ToString()) + Convert.ToInt16(numPatternG.Value.ToString()) - int.Parse(CAS200_txt0.Text)) >= 0)
            //        {
            //            if (numPatternR.Value * numPatternG.Value * numPatternB.Value == 0)
            //            {
            //                if (numPatternR.Value != 0)
            //                {
            //                    numPatternR.Value = (byte)(Convert.ToInt16(numPatternR.Value.ToString()) - int.Parse(CAS200_txt0.Text));
            //                }
            //                if (numPatternG.Value != 0)
            //                {
            //                    numPatternG.Value = (byte)(Convert.ToInt16(numPatternG.Value.ToString()) - int.Parse(CAS200_txt0.Text));
            //                }
            //                if (numPatternB.Value != 0)
            //                {
            //                    numPatternB.Value = (byte)(Convert.ToInt16(numPatternB.Value.ToString()) - int.Parse(CAS200_txt0.Text));
            //                }
            //            }
            //            else
            //            {
            //                numPatternB.Value = numPatternG.Value = numPatternR.Value = (byte)(Convert.ToInt16(numPatternR.Value.ToString()) - int.Parse(CAS200_txt0.Text));
            //            }
            //            Pattern_Write((byte)(numPatternR.Value), (byte)(numPatternG.Value), (byte)(numPatternB.Value));
            //        }
            //        else
            //        {
            //            T3.Enabled = false;
            //        }
            //    }
            //    Thread.Sleep(50);
            //    btn_CAS200_Synt_Click(btn_CAS200_Measure, null); //量测
        }

        private void btn_CAS200_Synt_Click(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;

            switch (btnTmp.Name)
            {
                case "btn_CAS200_Measure":
                    {
                        Msr_CA310();
                        CAS200_Measure_Information(auto_lum, auto_x, auto_y);
                    }
                    break;
                case "btn_CAS200Save":
                    {
                        SaveFileDialog sf = new SaveFileDialog(); //对话框
                        sf.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; //定义保存的文件的类型

                        string str = "序号,x坐标,y坐标,亮度\r\n";
                        if (sf.ShowDialog() == DialogResult.OK) //如果确定保存
                        {
                            if (sf.FileName == "") return; //如果没有输入文件名
                            try
                            {
                                StreamWriter sw = null; //文件流
                                sw = new StreamWriter(sf.FileName, false, Encoding.UTF8);
                                for (int i = 0; i < (this.CAS200_dataGridView.Rows.Count - 1); i++)
                                {
                                    str = str + this.CAS200_dataGridView.Rows[i].Cells[0].Value.ToString() + ","
                                        + this.CAS200_dataGridView.Rows[i].Cells[1].Value.ToString() + ","
                                        + this.CAS200_dataGridView.Rows[i].Cells[2].Value.ToString() + ","
                                        + this.CAS200_dataGridView.Rows[i].Cells[3].Value.ToString() + "\r\n";

                                }
                                sw.WriteLine(str);
                                sw.Dispose(); //释放资源
                                sw.Close(); //关闭数据流
                                MessageBox.Show("CA310数据保存OK！", "系统提示：");
                            }
                            catch
                            {
                                MessageBox.Show("CA310数据保存时发生错误，请再试！", "系统提示：");
                            }
                        }
                    }
                    break;
                case "btn_CAS200_load":
                    {
                        OpenFileDialog sf = new OpenFileDialog();
                        int Line_Count = 0;
                        string strtmp = "";
                        sf.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; //定义文件的类型
                        sf.Title = "数据导入";
                        if (sf.ShowDialog() == DialogResult.OK) //如果确定保存
                        {
                            FileStream fs = new FileStream(sf.FileName, FileMode.Open, FileAccess.Read);
                            StreamReader streamReader = new StreamReader(fs, Encoding.GetEncoding("GBK"));
                            streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
                            string strLine = streamReader.ReadLine();
                            while (!string.IsNullOrEmpty(strLine))
                            {
                                strtmp = strtmp + strLine + ",";
                                strLine = streamReader.ReadLine(); //循环读取下一行
                                Line_Count++;
                            }
                            fs.Close(); //关闭流
                            streamReader.Close();
                            string[] arrtmp = strtmp.Split(new Char[] { ',' });
                            for (int j = 1; j < Line_Count - 1; j++)
                            {
                                DataGridViewRow Row1 = new DataGridViewRow();
                                CAS200_dataGridView.Rows.Add(Row1);
                            }
                            try
                            {
                                for (int i = 0; i < Line_Count - 1; i++)//有一行标题
                                {
                                    CAS200_dataGridView.Rows[i].Cells[0].Value = arrtmp[4 * (i + 1) + 0];
                                    CAS200_dataGridView.Rows[i].Cells[1].Value = arrtmp[4 * (i + 1) + 1];
                                    CAS200_dataGridView.Rows[i].Cells[2].Value = arrtmp[4 * (i + 1) + 2];
                                    CAS200_dataGridView.Rows[i].Cells[3].Value = arrtmp[4 * (i + 1) + 3];
                                }
                                MessageBox.Show("CA310数据导入OK！", "提示：");
                            }
                            catch
                            {
                                MessageBox.Show("CA310数据导入时发生错误！", "提示：");
                            }
                        }
                    }
                    break;
                case "btn_CAS200_Clean":
                    {
                        DialogResult dr = MessageBox.Show("确认清空列表数据吗？", "系统提示", MessageBoxButtons.OKCancel);
                        if (dr == DialogResult.OK)
                        {
                            this.CAS200_dataGridView.Rows.Clear();
                        }
                        else {; }
                    }
                    break;
                case "btn_CAS200_Delect":
                    {
                        int Current_Index, Row_Accum;
                        Current_Index = this.CAS200_dataGridView.SelectedCells[0].RowIndex;
                        DataGridViewRow Row1 = CAS200_dataGridView.Rows[Current_Index];
                        this.CAS200_dataGridView.Rows.Remove(Row1);
                        this.CAS200_dataGridView.Rows[Current_Index].Selected = false;
                        Row_Accum = this.CAS200_dataGridView.Rows.Count - 1;
                        for (Current_Index = 0; Current_Index < Row_Accum; Current_Index++)
                        {
                            this.CAS200_dataGridView.Rows[Current_Index].Cells[0].Value = Current_Index + 1;//序号
                        }
                        this.CAS200_dataGridView.Rows[Row_Accum - 1].Selected = true;
                        CAS200_dataGridView.FirstDisplayedScrollingRowIndex = CAS200_dataGridView.RowCount - 1;
                    }
                    break;

                case "btn_CAS200_Stop":
                    {
                        T3.Enabled = false;
                    }
                    break;
                case "btn_CAS200_Start":
                    {
                        string strLine = Convert.ToString(text_CE_data.Text);
                        string[] arr = strLine.Split(','); //以逗号分割，添加到数组
                                                           //  Pattern_Write((byte)(numPatternR.Value), (byte)(numPatternG.Value), (byte)(numPatternB.Value));
                        CAS200_Measure_Count = 0;
                        CAS200_Measure_Gray = 255;
                        CA200_Measure_CE = byte.Parse((Convert.ToInt32(arr[arr.Length - 1], 16).ToString()));
                        T3.Enabled = true;
                        T3.Interval = int.Parse(CAS200_txt1.Text);//延时
                    }
                    break;
                default: break;
            }
        }

        private void btnCal_Click(object sender, EventArgs e)
        {
            OLED_Show_Click(btnblack, e);
            ca310info.Visible = true;
            try
            {
                Ca310Obj.CA310_Connect();
                Ca310Obj.CA310_Initial(byte.Parse(MainForm.CA310_Channel.Text));

                /*btnAutogamma350.Enabled = true;
                btnAutogammas350.Enabled = true;*/

                CAS200_dataGridView.Enabled = true;
                btn_CAS200Save.Enabled = true;
                btn_CAS200_Measure.Enabled = true;
                btn_CAS200_Clean.Enabled = true;
                btn_CAS200_Delect.Enabled = true;
                gBx_CAS200_Auto_Test.Enabled = true;
            }
            catch (Exception EX)
            {
                MessageBox.Show("CA310 Connect Fail!!" + EX.Message);
            }

            btnCal_manual.Text = "0Cal";
            ca310info.Visible = false;
            ca310info.Enabled = true;
        }

        private void Msr_CA310()
        {
            try
            {
                MainForm.Msr_CASDK();
                auto_lum = MainForm.CASDK_LUM;
                auto_x = MainForm.CASDK_x;
                auto_y = MainForm.CASDK_y;
            }
            catch
            {
                MessageBox.Show("请校准Senser！");
                //T17.Enabled = false;
                //return false;
            }
        }

        //=================================LCD cfg function: OLED_Show_Click====end=================     
        private int adjust_num = 0;
        private string adjust_class = null;
        private double[,] D_lums;//目标值-单色
        private double[] D_lum;//目标值-白色
        private double D_x, D_y;
        //private double lum_off, x_off, y_off;
        private int index = 0;
        //private int flag1 = 1;
        //private int flag2 = 1;
        //private int flag3 = 1;
        private int adjust_Rnum = 0;
        private int adjust_Gnum = 0;
        private int adjust_Bnum = 0;
        private int adjust_l = 0;
        private int adjust_x = 0;
        private int adjust_y = 0;
        //private int step_l = 1;
        //private int step_m = 5;
        //private int step_h = 12;
        Gamma_Addr GAMMAs = new Gamma_Addr();
        private ushort[] gamma_r = new ushort[31];
        private ushort[] gamma_g = new ushort[31];
        private ushort[] gamma_b = new ushort[31];
        private double lum_off, x_off, y_off;
        private double R_x = 0.67;//
        private double R_y = 0.33;
        private double G_x = 0.22;
        private double G_y = 0.71;

        private void btnBack_Click(object sender, EventArgs e)
        {
            MainForm.comPort.DataReceived -= new SerialDataReceivedEventHandler(SerialPort1_DataReceived);//移除本窗口串口处理函数
            MainForm.comPort.DataReceived += new SerialDataReceivedEventHandler(MainForm.SerialPort1_DataReceived);//
            MainForm.Show();
            this.Hide();
            frm_new_vtdr6110 = 0;
        }

        //private void rm69350_KeyDown(object sender, KeyEventArgs e)
        //{

        //    Thread.Sleep(100);
        //    if ((e.KeyCode == Keys.N) | (e.KeyCode == Keys.Left))// ;//&& Keys.A == e.KeyCode)
        //    {
        //        Demura_Function_ON.PerformClick();
        //    }
        //    else if ((e.KeyCode == Keys.M) | (e.KeyCode == Keys.Right))// ;//&& Keys.A == e.KeyCode)
        //    {
        //        Demura_Function_OFF.PerformClick();
        //    }
        //}


        private double B_x = 0.14;
        private double B_y = 0.06;
        //浏览图片
        private void btnReload_Click(object sender, EventArgs e)    //载入画面按键  选择文件夹
        {
            FolderBrowserDialog fldb = new FolderBrowserDialog();
            fldb.ShowNewFolderButton = false;
            DialogResult res = fldb.ShowDialog();
            if (res != System.Windows.Forms.DialogResult.OK)
            {
                MessageBox.Show("没选择任何文件夹.");
                return;
            }
            string path = fldb.SelectedPath;
            if (!Directory.Exists(path))
            {
                MessageBox.Show("文件夹不存在.");
                return;
            }
            DirectoryInfo di = new DirectoryInfo(path);
            this.listBox3_BMPFile.Items.Clear();
            this.CreateListItem(di);//递归加载文件夹里的所有图片
            textBox2.Text = path;
        }
        /// <summary>
        /// 递归文件夹，把文件夹里所有后缀类似图片的文件，加入listbox
        /// </summary>
        /// <param name="di"></param>
        private void CreateListItem(DirectoryInfo di)
        {
            foreach (DirectoryInfo childDi in di.GetDirectories())
            {
                this.CreateListItem(childDi);
            }
            foreach (FileInfo fi in di.GetFiles())
            {
                if (ImageType.Contains(fi.Extension))//找到一个图片(如果用户手贱把一个excel文件后缀改成jpeg没办法)
                {
                    this.listBox3_BMPFile.Items.Add(new MyImage(fi.FullName));
                }
            }
        }
        private void lstImage_Click(object sender, EventArgs e)
        {
            if (listBox3_BMPFile.SelectedItem == null)
            {
                return;
            }
            MyImage selectedImg = (MyImage)listBox3_BMPFile.SelectedItem;
            Image img = new Bitmap(selectedImg.Path);
            pictureBox1.Image = img;
        }
        System.DateTime TimeNow2 = new DateTime();
        TimeSpan TimeCount2 = new TimeSpan();
        private void btnPrevPic_Click(object sender, EventArgs e)
        {
            FileStream aFile;
            Int32 m_txlen = 0;

            int HACT_True;
            int VACT_True;
            int j;
            TimeNow2 = DateTime.Now; //开始计时

            byte[] TemFileContent = new byte[512 * 4000 + 100];
            int ByteReaded = 0x00;

            string FileName = textBox2.Text + '\\' + listBox3_BMPFile.SelectedItem.ToString();

            aFile = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            ByteReaded = aFile.Read(TemFileContent, 0, 54);

            HACT_True = ((TemFileContent[19]) << 8) + TemFileContent[18];
            VACT_True = ((TemFileContent[23] << 8) + TemFileContent[22]);
            if (MainForm.HACT.Value != HACT_True)
            {
                textBox1.Text += "图片宽度与设定不符\r\n";
                return;
            }

            if ((MainForm.Dis_mode.SelectedIndex == 1)) //(Dis_mode.SelectedIndex == 1):MIPI 模式，因为下位机仅对MIPI模式做了优化
            {
                //------------20180903---------------
                try
                {   //bd 5a a5 9DF0-----提前下个标志位告诉下位机开始送图了，避免特殊图片格式导致错误配置
                    //BD A5 5A 9DF0-----提前下个标志位告诉下位机开始 快速 送图了
                    TemFileContent[0] = 0xbd; TemFileContent[1] = 0xa5; TemFileContent[2] = 0x5a; TemFileContent[3] = 0x9d; TemFileContent[4] = 0xf0;
                    MainForm.comPort.Write(TemFileContent, 0, 5);
                }
                catch
                {
                    MessageBox.Show("串口有误，请检查", "错误");
                    return;
                }
                //-----------------------------------
                try
                {
                    j = 0;
                    int x, y, s = 0;
                    x = 512 * 4000; //单次传输数量
                    y = (VACT_True * HACT_True * 3 / x); //传输次数
                    if ((VACT_True * HACT_True * 3 % x) != 0)
                        y++;
                    {
                        //aFile.Seek(54, SeekOrigin.Begin);
                        while (j < y)
                        {
                            //if (HACT_True % 4 != 0)
                            //    aFile.Seek((VACT_True - j) * (HACT_True * 3 + (HACT_True % 4)) + 54, SeekOrigin.Begin);
                            //else
                            //    aFile.Seek((VACT_True - j) * HACT_True * 3 + 54, SeekOrigin.Begin);
                            aFile.Seek((j) * x + 54, SeekOrigin.Begin);

                            ByteReaded = aFile.Read(TemFileContent, 0, x);

                            try
                            {
                                MainForm.comPort.Write(TemFileContent, 0, ByteReaded);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                                break;
                            }

                            progressBar1.Value = Convert.ToInt32((double)m_txlen / aFile.Length * 100);
                            label14.Text = progressBar1.Value.ToString() + "%";
                            Application.DoEvents();
                            j++;
                        }

                        TemFileContent[0] = 0x5A;
                        try
                        {
                            MainForm.comPort.Write(TemFileContent, 0, 1);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }

                        aFile.Close();
                    }
                }
                catch
                {
                    MessageBox.Show("请选择文件夹", "错误");
                }
            }
            else
            {
                //------------20180808---------------
                try
                { //5a a5 9DF0731A-----提前下个标志位告诉下位机开始送图了，避免特殊图片格式导致错误配置
                    TemFileContent[0] = 0xbd; TemFileContent[1] = 0x5a; TemFileContent[2] = 0xa5; TemFileContent[3] = 0x9d; TemFileContent[4] = 0xf0;
                    MainForm.comPort.Write(TemFileContent, 0, 5);
                }
                catch
                {
                    MessageBox.Show("串口有误，请检查", "错误");
                    return;
                }
                //-----------------------------------
                try
                {
                    j = 1;
                    //if ((HACT_True == ((TemFileContent[19] << 8) + (TemFileContent[18]))) && (Convert.ToInt32(VACT.Value) == (TemFileContent[23] << 8) + (TemFileContent[22])))//BMP图片水平大小
                    {
                        aFile.Seek(54, SeekOrigin.Begin);
                        while (j <= VACT_True)
                        {
                            if (HACT_True % 4 != 0)
                                aFile.Seek((VACT_True - j) * (HACT_True * 3 + (HACT_True % 4)) + 54, SeekOrigin.Begin);
                            else
                                aFile.Seek((VACT_True - j) * HACT_True * 3 + 54, SeekOrigin.Begin);


                            ByteReaded = aFile.Read(TemFileContent, 0, HACT_True * 3); // 

                            try
                            {
                                MainForm.comPort.Write(TemFileContent, 0, ByteReaded);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                                break;
                            }
                            m_txlen += ByteReaded;
                            progressBar1.Value = Convert.ToInt32((double)m_txlen / aFile.Length * 100);
                            label14.Text = progressBar1.Value.ToString() + "%";
                            Application.DoEvents();//重点，必须加上，否则父子窗体都假死
                            j++;
                        }

                        TemFileContent[0] = 0x5A;
                        try
                        {
                            MainForm.comPort.Write(TemFileContent, 0, 1);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                            return;
                        }

                        aFile.Close();
                    }
                    /*
                    else
                    {
                        MessageBox.Show("BMP分辨率非法");
                    }*/
                }
                catch
                {
                    textBox1.Text += "啥图片都没显示";
                    textBox1.Select(textBox1.Text.Length, 0);
                    textBox1.ScrollToCaret();
                }
            }


            TimeCount2 = DateTime.Now - TimeNow2;
            textBox1.Text = string.Format("{0:00}:{1:00}", TimeCount2.Seconds, TimeCount2.Milliseconds);
        }
        public class MyImage
        {
            public MyImage(string p)
            {
                this.Path = p;
            }
            public string Path { get; set; }
            public override string ToString()
            {
                if (Path == null)
                {
                    return null;
                }
                return System.IO.Path.GetFileName(this.Path);
            }
        }

        /*private void radio_Gamma3_CheckedChanged(object sender, EventArgs e)
        {
            Send_buf = new byte[7];
            Setting.TempRecord.cmdLen = 7;

            Send_buf[0] = 0x3C;
            Send_buf[2] = 0x02;

            RadioButton btnTmp = (RadioButton)sender;
            Setting.TempRecord.RM69350CmdType = 0x06;       //      6
            if (RM350_radioGamma1.Checked == true)
            {
                Send_buf[1] = 0x11;
                Send_buf[3] = 0x01;

            }
            else if (RM350_radioGamma2.Checked == true)
            {
                Send_buf[1] = 0x11;
                Send_buf[3] = 0x02;
            }
            else if (RM350_radioGamma3.Checked == true)
            {
                Send_buf[1] = 0x11;
                Send_buf[3] = 0x03;
            }
            if (radioButton12.Checked == true)
            {
                Send_buf[4] = 0x01;
            }
            else
            {
                Send_buf[4] = 0x02;
            }
            CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
            try
            {
                RM350_0XFE_XX = 0x00;
                MainForm.comPort.Write(Send_buf, 0, 7);
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
            T1.Enabled = false;
            T1.Interval = 2000;
            T1.Enabled = true;
        }*/

        /*private void RM350_Others_Click(object sender, EventArgs e)
        {
            Send_buf = new byte[7];
            Button btnTmp = (Button)sender;
            Setting.TempRecord.cmdLen = 7;

            Send_buf[0] = 0x3C;        //RM69350
            Send_buf[2] = 0x02;
            switch (btnTmp.Name)
            {
                case "RM69350_Reg_R":       //              2
                    {
                        RM350_0XFE_XX = 0x00;
                        Setting.TempRecord.RM69350CmdType = 0x01;   //读普通寄存器    1
                        Send_buf[1] = 0x02;
                        Send_buf[3] = byte.Parse((Convert.ToInt32(R69350_Reg_Addr.Text.Trim(), 16)).ToString());
                    }
                    break;
                case "RM69350_51Reg_W":       //              2
                    {

                        Send_buf[1] = 0x51;
                        Send_buf[3] = byte.Parse((Convert.ToInt32(R69350_Reg_Addr.Text.Trim(), 16)).ToString());
                        Send_buf[4] = byte.Parse((Convert.ToInt32(R69350_Reg_Data.Text.Trim(), 16)).ToString());
                        CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
                        MainForm.comPort.Write(Send_buf, 0, 7);
                        return;
                    }
                    //break;
                case "RM69350_Reg_W":         //w写寄存器   1
                    {
                        RM350_0XFE_XX = 0x00;
                        Send_buf[1] = 0x01;
                        Send_buf[3] = byte.Parse((Convert.ToInt32(R69350_Reg_Addr.Text.Trim(), 16)).ToString());
                        Send_buf[4] = byte.Parse((Convert.ToInt32(R69350_Reg_Data.Text.Trim(), 16)).ToString());
                    }
                    break;
                case "RM69350_R_OTPTime":       //          B
                    {
                        RM350_0XFE_XX = 0x00;
                        Send_buf[1] = 0x0B;
                        Setting.TempRecord.RM69350CmdType = 0x02;       //      2
                        if (radioButton17.Checked == true)
                        {
                            Send_buf[3] = 0x00;
                        }
                        else if (radioButton16.Checked == true)
                        {
                            Send_buf[3] = 0x01;
                        }
                        else if (radioButton15.Checked == true)
                        {
                            Send_buf[3] = 0x02;
                        }
                        else if (radioButton14.Checked == true)
                        {
                            Send_buf[3] = 0x03;
                        }
                        else if (radioButton13.Checked == true)
                        {
                            Send_buf[3] = 0x04;
                        }
                    }
                    break;
                case "RM69350_W_OTPTime":         //w写寄存器   C
                    {
                        RM350_0XFE_XX = 0x00;
                        if (Convert.ToDecimal(textBox68.Text) > 3)
                        {
                            MessageBox.Show("OTP次数不能大于3次", "警告");
                            return;
                        }
                        else
                        {
                            Send_buf[1] = 0x0C;
                            Send_buf[4] = byte.Parse((Convert.ToInt32(textBox68.Text.Trim(), 16)).ToString());
                        }
                    }
                    break;

                default:
                    break;
            }
            CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
            try
            {
                MainForm.comPort.Write(Send_buf, 0, 7);
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
            T1.Enabled = false;
            T1.Interval = 2000;
            T1.Enabled = true;
        }*/

        /*private void RM350_Gamma_Click(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;
            Send_buf = new byte[62];
            Setting.TempRecord.cmdLen = 62;
            Send_buf[2] = 57;
            Send_buf[3] = 0;
            Send_buf[0] = 0x3C; //RM69350


            switch (btnTmp.Name)
            {
                case "RM69350_GammaR_Red":
                    {
                        Setting.TempRecord.RM69350CmdType = 0x03;       //      3
                        Send_buf[1] = 0x09;                             //读Gamma
                        Send_buf[3] |= 0x00;                            //红色red
                        if (RM350_radioGamma1.Checked == true)
                        {
                            Send_buf[4] = 0x00;
                        }
                        else if (RM350_radioGamma2.Checked == true)
                        {
                            Send_buf[4] = 0x01;
                        }
                        else if (RM350_radioGamma3.Checked == true)
                        {
                            Send_buf[4] = 0x02;
                        }
                    }
                    break;
                case "RM69350_GammaR_Green":
                    {
                        Setting.TempRecord.RM69350CmdType = 0x04;   //      4
                        Send_buf[1] = 0x09;                         //  读Gamma
                        Send_buf[3] |= 0x42;                        //绿色 green
                        if (RM350_radioGamma1.Checked == true)
                        {
                            Send_buf[4] = 0x00;
                        }
                        else if (RM350_radioGamma2.Checked == true)
                        {
                            Send_buf[4] = 0x01;
                        }
                        else if (RM350_radioGamma3.Checked == true)
                        {
                            Send_buf[4] = 0x02;
                        }
                    }
                    break;
                case "RM69350_GammaR_Blue": //              9
                    {
                        Setting.TempRecord.RM69350CmdType = 0x05;   //      5
                        Send_buf[1] = 0x09;                         //   读Gamma
                        Send_buf[3] |= 0x81;                        //   blue
                        if (RM350_radioGamma1.Checked == true)
                        {
                            Send_buf[4] = 0x00;
                        }
                        else if (RM350_radioGamma2.Checked == true)
                        {
                            Send_buf[4] = 0x01;
                        }
                        else if (RM350_radioGamma3.Checked == true)
                        {
                            Send_buf[4] = 0x02;
                        }
                    }
                    break;
                //--------------------------------------
                case "RM69350_GammaW_Red":
                    {
                        Send_buf[1] = 0x08;                       //写Gamma
                        if (RM350_radioGamma1.Checked == true)
                        {
                            Send_buf[3] = 0x00;
                        }
                        else if (RM350_radioGamma2.Checked == true)
                        {
                            Send_buf[3] = 0x01;
                        }
                        else if (RM350_radioGamma3.Checked == true)
                        {
                            Send_buf[3] = 0x02;
                        }
                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R0.Value.ToString()) >> 8);
                        Send_buf[5] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R0.Value.ToString())) & 0xff);
                        Send_buf[6] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R1.Value.ToString()) >> 8);
                        Send_buf[7] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R1.Value.ToString())) & 0xff);
                        Send_buf[8] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R3.Value.ToString()) >> 8);
                        Send_buf[9] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R3.Value.ToString())) & 0xff);
                        Send_buf[10] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R5.Value.ToString()) >> 8);
                        Send_buf[11] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R5.Value.ToString())) & 0xff);
                        Send_buf[12] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R7.Value.ToString()) >> 8);
                        Send_buf[13] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R7.Value.ToString())) & 0xff);
                        Send_buf[14] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R11.Value.ToString()) >> 8);
                        Send_buf[15] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R11.Value.ToString())) & 0xff);
                        Send_buf[16] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R15.Value.ToString()) >> 8);
                        Send_buf[17] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R15.Value.ToString())) & 0xff);
                        Send_buf[18] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R19.Value.ToString()) >> 8);
                        Send_buf[19] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R19.Value.ToString())) & 0xff);
                        Send_buf[20] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R23.Value.ToString()) >> 8);
                        Send_buf[21] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R23.Value.ToString())) & 0xff);
                        Send_buf[22] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R27.Value.ToString()) >> 8);
                        Send_buf[23] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R27.Value.ToString())) & 0xff);
                        Send_buf[24] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R31.Value.ToString()) >> 8);
                        Send_buf[25] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R31.Value.ToString())) & 0xff);
                        Send_buf[26] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R35.Value.ToString()) >> 8);
                        Send_buf[27] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R35.Value.ToString())) & 0xff);
                        Send_buf[28] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R39.Value.ToString()) >> 8);
                        Send_buf[29] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R39.Value.ToString())) & 0xff);
                        Send_buf[30] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R47.Value.ToString()) >> 8);
                        Send_buf[31] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R47.Value.ToString())) & 0xff);
                        Send_buf[32] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R55.Value.ToString()) >> 8);
                        Send_buf[33] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R55.Value.ToString())) & 0xff);
                        Send_buf[34] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R63.Value.ToString()) >> 8);
                        Send_buf[35] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R63.Value.ToString())) & 0xff);
                        Send_buf[36] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R71.Value.ToString()) >> 8);
                        Send_buf[37] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R71.Value.ToString())) & 0xff);
                        Send_buf[38] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R79.Value.ToString()) >> 8);
                        Send_buf[39] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R79.Value.ToString())) & 0xff);
                        Send_buf[40] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R95.Value.ToString()) >> 8);
                        Send_buf[41] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R95.Value.ToString())) & 0xff);
                        Send_buf[42] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R111.Value.ToString()) >> 8);
                        Send_buf[43] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R111.Value.ToString())) & 0xff);
                        Send_buf[44] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R127.Value.ToString()) >> 8);
                        Send_buf[45] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R127.Value.ToString())) & 0xff);
                        Send_buf[46] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R159.Value.ToString()) >> 8);
                        Send_buf[47] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R159.Value.ToString())) & 0xff);
                        Send_buf[48] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R191.Value.ToString()) >> 8);
                        Send_buf[49] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R191.Value.ToString())) & 0xff);
                        Send_buf[50] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R223.Value.ToString()) >> 8);
                        Send_buf[51] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R223.Value.ToString())) & 0xff);
                        Send_buf[52] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R255.Value.ToString()) >> 8);
                        Send_buf[53] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R255.Value.ToString())) & 0xff);
                        Send_buf[54] = Convert.ToByte(Convert.ToUInt16(rm350_R223.Value.ToString()) >> 8);
                        Send_buf[55] = Convert.ToByte((Convert.ToUInt16(rm350_R223.Value.ToString())) & 0xff);
                        Send_buf[56] = Convert.ToByte(Convert.ToUInt16(rm350_R239.Value.ToString()) >> 8);
                        Send_buf[57] = Convert.ToByte((Convert.ToUInt16(rm350_R239.Value.ToString())) & 0xff);
                        Send_buf[58] = Convert.ToByte(Convert.ToUInt16(rm350_R255.Value.ToString()) >> 8);
                        Send_buf[59] = Convert.ToByte((Convert.ToUInt16(rm350_R255.Value.ToString())) & 0xff);
                    }
                    break;
                case "RM69350_GammaW_Green":
                    {
                        Send_buf[1] = 0x08;
                        if (RM350_radioGamma1.Checked == true)
                        {
                            Send_buf[3] = 0x40;
                        }
                        else if (RM350_radioGamma2.Checked == true)
                        {
                            Send_buf[3] = 0x41;
                        }
                        else if (RM350_radioGamma3.Checked == true)
                        {
                            Send_buf[3] = 0x42;
                        }
                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G0.Value.ToString()) >> 8);
                        Send_buf[5] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G0.Value.ToString())) & 0xff);
                        Send_buf[6] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G1.Value.ToString()) >> 8);
                        Send_buf[7] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G1.Value.ToString())) & 0xff);
                        Send_buf[8] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G3.Value.ToString()) >> 8);
                        Send_buf[9] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G3.Value.ToString())) & 0xff);
                        Send_buf[10] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G5.Value.ToString()) >> 8);
                        Send_buf[11] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G5.Value.ToString())) & 0xff);
                        Send_buf[12] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G7.Value.ToString()) >> 8);
                        Send_buf[13] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G7.Value.ToString())) & 0xff);
                        Send_buf[14] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G11.Value.ToString()) >> 8);
                        Send_buf[15] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G11.Value.ToString())) & 0xff);
                        Send_buf[16] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G15.Value.ToString()) >> 8);
                        Send_buf[17] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G15.Value.ToString())) & 0xff);
                        Send_buf[18] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G19.Value.ToString()) >> 8);
                        Send_buf[19] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G19.Value.ToString())) & 0xff);
                        Send_buf[20] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G23.Value.ToString()) >> 8);
                        Send_buf[21] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G23.Value.ToString())) & 0xff);
                        Send_buf[22] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G27.Value.ToString()) >> 8);
                        Send_buf[23] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G27.Value.ToString())) & 0xff);
                        Send_buf[24] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G31.Value.ToString()) >> 8);
                        Send_buf[25] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G31.Value.ToString())) & 0xff);
                        Send_buf[26] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G35.Value.ToString()) >> 8);
                        Send_buf[27] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G35.Value.ToString())) & 0xff);
                        Send_buf[28] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G39.Value.ToString()) >> 8);
                        Send_buf[29] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G39.Value.ToString())) & 0xff);
                        Send_buf[30] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G47.Value.ToString()) >> 8);
                        Send_buf[31] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G47.Value.ToString())) & 0xff);
                        Send_buf[32] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G55.Value.ToString()) >> 8);
                        Send_buf[33] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G55.Value.ToString())) & 0xff);
                        Send_buf[34] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G63.Value.ToString()) >> 8);
                        Send_buf[35] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G63.Value.ToString())) & 0xff);
                        Send_buf[36] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G71.Value.ToString()) >> 8);
                        Send_buf[37] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G71.Value.ToString())) & 0xff);
                        Send_buf[38] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G79.Value.ToString()) >> 8);
                        Send_buf[39] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G79.Value.ToString())) & 0xff);
                        Send_buf[40] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G95.Value.ToString()) >> 8);
                        Send_buf[41] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G95.Value.ToString())) & 0xff);
                        Send_buf[42] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G111.Value.ToString()) >> 8);
                        Send_buf[43] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G111.Value.ToString())) & 0xff);
                        Send_buf[44] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G127.Value.ToString()) >> 8);
                        Send_buf[45] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G127.Value.ToString())) & 0xff);
                        Send_buf[46] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G159.Value.ToString()) >> 8);
                        Send_buf[47] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G159.Value.ToString())) & 0xff);
                        Send_buf[48] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G191.Value.ToString()) >> 8);
                        Send_buf[49] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G191.Value.ToString())) & 0xff);
                        Send_buf[50] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G223.Value.ToString()) >> 8);
                        Send_buf[51] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G223.Value.ToString())) & 0xff);
                        Send_buf[52] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G255.Value.ToString()) >> 8);
                        Send_buf[53] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G255.Value.ToString())) & 0xff);
                        Send_buf[54] = Convert.ToByte(Convert.ToUInt16(rm350_G223.Value.ToString()) >> 8);
                        Send_buf[55] = Convert.ToByte((Convert.ToUInt16(rm350_G223.Value.ToString())) & 0xff);
                        Send_buf[56] = Convert.ToByte(Convert.ToUInt16(rm350_G239.Value.ToString()) >> 8);
                        Send_buf[57] = Convert.ToByte((Convert.ToUInt16(rm350_G239.Value.ToString())) & 0xff);
                        Send_buf[58] = Convert.ToByte(Convert.ToUInt16(rm350_G255.Value.ToString()) >> 8);
                        Send_buf[59] = Convert.ToByte((Convert.ToUInt16(rm350_G255.Value.ToString())) & 0xff);
                    }
                    break;
                case "RM69350_GammaW_Blue":     //      8
                    {
                        Send_buf[1] = 0x08;
                        if (RM350_radioGamma1.Checked == true)
                        {
                            Send_buf[3] = 0x80;
                        }
                        else if (RM350_radioGamma2.Checked == true)
                        {
                            Send_buf[3] = 0x81;
                        }
                        else if (RM350_radioGamma3.Checked == true)
                        {
                            Send_buf[3] = 0x82;
                        }

                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B0.Value.ToString()) >> 8);
                        Send_buf[5] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B0.Value.ToString())) & 0xff);
                        Send_buf[6] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B1.Value.ToString()) >> 8);
                        Send_buf[7] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B1.Value.ToString())) & 0xff);
                        Send_buf[8] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B3.Value.ToString()) >> 8);
                        Send_buf[9] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B3.Value.ToString())) & 0xff);
                        Send_buf[10] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B5.Value.ToString()) >> 8);
                        Send_buf[11] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B5.Value.ToString())) & 0xff);
                        Send_buf[12] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B7.Value.ToString()) >> 8);
                        Send_buf[13] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B7.Value.ToString())) & 0xff);
                        Send_buf[14] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B11.Value.ToString()) >> 8);
                        Send_buf[15] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B11.Value.ToString())) & 0xff);
                        Send_buf[16] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B15.Value.ToString()) >> 8);
                        Send_buf[17] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B15.Value.ToString())) & 0xff);
                        Send_buf[18] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B19.Value.ToString()) >> 8);
                        Send_buf[19] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B19.Value.ToString())) & 0xff);
                        Send_buf[20] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B23.Value.ToString()) >> 8);
                        Send_buf[21] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B23.Value.ToString())) & 0xff);
                        Send_buf[22] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B27.Value.ToString()) >> 8);
                        Send_buf[23] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B27.Value.ToString())) & 0xff);
                        Send_buf[24] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B31.Value.ToString()) >> 8);
                        Send_buf[25] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B31.Value.ToString())) & 0xff);
                        Send_buf[26] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B35.Value.ToString()) >> 8);
                        Send_buf[27] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B35.Value.ToString())) & 0xff);
                        Send_buf[28] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B39.Value.ToString()) >> 8);
                        Send_buf[29] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B39.Value.ToString())) & 0xff);
                        Send_buf[30] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B47.Value.ToString()) >> 8);
                        Send_buf[31] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B47.Value.ToString())) & 0xff);
                        Send_buf[32] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B55.Value.ToString()) >> 8);
                        Send_buf[33] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B55.Value.ToString())) & 0xff);
                        Send_buf[34] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B63.Value.ToString()) >> 8);
                        Send_buf[35] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B63.Value.ToString())) & 0xff);
                        Send_buf[36] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B71.Value.ToString()) >> 8);
                        Send_buf[37] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B71.Value.ToString())) & 0xff);
                        Send_buf[38] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B79.Value.ToString()) >> 8);
                        Send_buf[39] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B79.Value.ToString())) & 0xff);
                        Send_buf[40] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B95.Value.ToString()) >> 8);
                        Send_buf[41] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B95.Value.ToString())) & 0xff);
                        Send_buf[42] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B111.Value.ToString()) >> 8);
                        Send_buf[43] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B111.Value.ToString())) & 0xff);
                        Send_buf[44] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B127.Value.ToString()) >> 8);
                        Send_buf[45] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B127.Value.ToString())) & 0xff);
                        Send_buf[46] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B159.Value.ToString()) >> 8);
                        Send_buf[47] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B159.Value.ToString())) & 0xff);
                        Send_buf[48] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B191.Value.ToString()) >> 8);
                        Send_buf[49] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B191.Value.ToString())) & 0xff);
                        Send_buf[50] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B223.Value.ToString()) >> 8);
                        Send_buf[51] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B223.Value.ToString())) & 0xff);
                        Send_buf[52] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B255.Value.ToString()) >> 8);
                        Send_buf[53] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B255.Value.ToString())) & 0xff);
                        Send_buf[54] = Convert.ToByte(Convert.ToUInt16(rm350_B223.Value.ToString()) >> 8);
                        Send_buf[55] = Convert.ToByte((Convert.ToUInt16(rm350_B223.Value.ToString())) & 0xff);
                        Send_buf[56] = Convert.ToByte(Convert.ToUInt16(rm350_B239.Value.ToString()) >> 8);
                        Send_buf[57] = Convert.ToByte((Convert.ToUInt16(rm350_B239.Value.ToString())) & 0xff);
                        Send_buf[58] = Convert.ToByte(Convert.ToUInt16(rm350_B255.Value.ToString()) >> 8);
                        Send_buf[59] = Convert.ToByte((Convert.ToUInt16(rm350_B255.Value.ToString())) & 0xff);

                    }
                    break;
                default:
                    break;
            }
            CRCData.CalculateCrc16(Send_buf, out Send_buf[60], out Send_buf[61]);
            try
            {
                RM350_0XFE_XX = 0x00;
                MainForm.comPort.Write(Send_buf, 0, 62);   //RM69350
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
            T1.Enabled = false;
            T1.Interval = 2000;
            T1.Enabled = true;
        }*/



        /* private void trackBar2_Scroll(object sender, EventArgs e)
         {
             R69350_51Reg.Text = trackBar_RM69350.Value.ToString() + "阶";
             if (RM350_0XFE_XX != 0xF0)
             {
                 RM350_0XFE_XX = 0xF0;
                 R69350_Reg_Addr.Text = "fe";
                 R69350_Reg_Data.Text = "00";
                 RM350_Others_Click(RM69350_51Reg_W, e);
             }
             R69350_Reg_Addr.Text = "51";
             R69350_Reg_Data.Text = trackBar_RM69350.Value.ToString("x2");
             RM350_Others_Click(RM69350_51Reg_W, e);
         }*/



        /* private void RM350_OTP_Click(object sender, EventArgs e)
         {
             Send_buf = new byte[7];
             Button btnTmp = (Button)sender;
             Setting.TempRecord.cmdLen = 7;

             Send_buf[0] = 0x3C;        //RM69350
             Send_buf[2] = 0x02;

             switch (btnTmp.Name)
             {
                 case "RM350_OTP_GammaSet1": //otp GammaSet1       A
                     {
                         RM350_0XFE_XX = 0x00;
                         Send_buf[1] = 0x0B;
                         Setting.TempRecord.RM69350CmdType = 0x02;
                         Send_buf[3] = 0x00;
                         CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
                         try
                         {
                             MainForm.comPort.Write(Send_buf, 0, 7);
                         }
                         catch
                         {
                             MessageBox.Show("串口有误，请检查", "错误");
                         }
                         T1.Enabled = false;
                         T1.Interval = 2000;
                         T1.Enabled = true;

                         Delay(100);

                         if (radioButton17.Checked == true)
                         {
                             RM350_0XFE_XX = 0x00;
                             if (Convert.ToDecimal(textBox68.Text) > 3)
                             {
                                 MessageBox.Show("OTP次数不能大于3次", "警告");
                                 return;
                             }
                             else
                             {
                                 RM350_0XFE_XX = 0x00;
                                 Send_buf[1] = 0x0A;

                                 CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
                                 try
                                 {
                                     MainForm.comPort.Write(Send_buf, 0, 7);
                                 }
                                 catch
                                 {
                                     MessageBox.Show("串口有误，请检查", "错误");
                                 }
                                 T1.Enabled = false;
                                 T1.Interval = 2000;
                                 T1.Enabled = true;
                             }
                         }

                     }
                     break;
                 case "RM350_OTP_GammaSet2"://otp GammaSet2        D
                     {
                         RM350_0XFE_XX = 0x00;
                         Send_buf[1] = 0x0B;
                         Setting.TempRecord.RM69350CmdType = 0x02;
                         Send_buf[3] = 0x01;
                         CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
                         try
                         {
                             MainForm.comPort.Write(Send_buf, 0, 7);
                         }
                         catch
                         {
                             MessageBox.Show("串口有误，请检查", "错误");
                         }
                         T1.Enabled = false;
                         T1.Interval = 2000;
                         T1.Enabled = true;

                         Delay(100);

                         if (radioButton16.Checked == true)
                         {
                             RM350_0XFE_XX = 0x00;
                             if (Convert.ToDecimal(textBox68.Text) > 3)
                             {
                                 MessageBox.Show("OTP次数不能大于3次", "警告");
                                 return;
                             }
                             else
                             {
                                 RM350_0XFE_XX = 0x00;
                                 Send_buf[1] = 0x0D;

                                 CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
                                 try
                                 {
                                     MainForm.comPort.Write(Send_buf, 0, 7);
                                 }
                                 catch
                                 {
                                     MessageBox.Show("串口有误，请检查", "错误");
                                 }
                                 T1.Enabled = false;
                                 T1.Interval = 2000;
                                 T1.Enabled = true;
                             }
                         }
                     }
                     break;
                 case "RM350_OTP_GammaSet3"://otp GammaSet3        E
                     {
                         RM350_0XFE_XX = 0x00;
                         Send_buf[1] = 0x0B;
                         Setting.TempRecord.RM69350CmdType = 0x02;
                         Send_buf[3] = 0x02;
                         CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
                         try
                         {
                             MainForm.comPort.Write(Send_buf, 0, 7);
                         }
                         catch
                         {
                             MessageBox.Show("串口有误，请检查", "错误");
                         }
                         T1.Enabled = false;
                         T1.Interval = 2000;
                         T1.Enabled = true;

                         Delay(100);

                         if (radioButton15.Checked == true)
                         {
                             RM350_0XFE_XX = 0x00;
                             if (Convert.ToDecimal(textBox68.Text) > 3)
                             {
                                 MessageBox.Show("OTP次数不能大于3次", "警告");
                                 return;
                             }
                             else
                             {
                                 RM350_0XFE_XX = 0x00;
                                 Send_buf[1] = 0x0E;

                                 CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
                                 try
                                 {
                                     MainForm.comPort.Write(Send_buf, 0, 7);
                                 }
                                 catch
                                 {
                                     MessageBox.Show("串口有误，请检查", "错误");
                                 }
                                 T1.Enabled = false;
                                 T1.Interval = 2000;
                                 T1.Enabled = true;
                             }
                         }
                     }
                     break;
                 case "RM350_OTP_GOA"://otp goa                    F
                     {
                         RM350_0XFE_XX = 0x00;
                         Send_buf[1] = 0x0B;
                         Setting.TempRecord.RM69350CmdType = 0x02;
                         Send_buf[3] = 0x03;
                         CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
                         try
                         {
                             MainForm.comPort.Write(Send_buf, 0, 7);
                         }
                         catch
                         {
                             MessageBox.Show("串口有误，请检查", "错误");
                         }
                         T1.Enabled = false;
                         T1.Interval = 2000;
                         T1.Enabled = true;

                         Delay(100);

                         if (radioButton14.Checked == true)
                         {
                             RM350_0XFE_XX = 0x00;
                             if (Convert.ToDecimal(textBox68.Text) > 3)
                             {
                                 MessageBox.Show("OTP次数不能大于3次", "警告");
                                 return;
                             }
                             else
                             {
                                 RM350_0XFE_XX = 0x00;
                                 Send_buf[1] = 0x0F;

                                 CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
                                 try
                                 {
                                     MainForm.comPort.Write(Send_buf, 0, 7);
                                 }
                                 catch
                                 {
                                     MessageBox.Show("串口有误，请检查", "错误");
                                 }
                                 T1.Enabled = false;
                                 T1.Interval = 2000;
                                 T1.Enabled = true;
                             }
                         }
                     }
                     break;
                 case "RM350_OTP_Power"://otp power                10
                     {
                         RM350_0XFE_XX = 0x00;
                         Send_buf[1] = 0x0B;
                         Setting.TempRecord.RM69350CmdType = 0x02;
                         Send_buf[3] = 0x04;
                         CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
                         try
                         {
                             MainForm.comPort.Write(Send_buf, 0, 7);
                         }
                         catch
                         {
                             MessageBox.Show("串口有误，请检查", "错误");
                         }
                         T1.Enabled = false;
                         T1.Interval = 2000;
                         T1.Enabled = true;

                         Delay(100);

                         if (radioButton13.Checked == true)
                         {
                             RM350_0XFE_XX = 0x00;
                             if (Convert.ToDecimal(textBox68.Text) > 3)
                             {
                                 MessageBox.Show("OTP次数不能大于3次", "警告");
                                 return;
                             }
                             else
                             {
                                 RM350_0XFE_XX = 0x00;
                                 Send_buf[1] = 0x10;

                                 CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
                                 try
                                 {
                                     MainForm.comPort.Write(Send_buf, 0, 7);
                                 }
                                 catch
                                 {
                                     MessageBox.Show("串口有误，请检查", "错误");
                                 }
                                 T1.Enabled = false;
                                 T1.Interval = 2000;
                                 T1.Enabled = true;
                             }
                         }
                     }
                     break;
                 case "RM350_OTP_SPR"://otp power                10
                     {
                         RM350_0XFE_XX = 0x00;
                         Send_buf[1] = 0x0B;
                         Setting.TempRecord.RM69350CmdType = 0x02;
                         Send_buf[3] = 0x00;
                         CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
                         try
                         {
                             MainForm.comPort.Write(Send_buf, 0, 7);
                         }
                         catch
                         {
                             MessageBox.Show("串口有误，请检查", "错误");
                         }
                         T1.Enabled = false;
                         T1.Interval = 2000;
                         T1.Enabled = true;

                         Delay(100);

                         if (radioButton17.Checked == true)
                         {
                             RM350_0XFE_XX = 0x00;
                             if (Convert.ToDecimal(textBox68.Text) > 3)
                             {
                                 MessageBox.Show("OTP次数不能大于3次", "警告");
                                 return;
                             }
                             else
                             {
                                 RM350_0XFE_XX = 0x00;
                                 Send_buf[1] = 0x0A;

                                 CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
                                 try
                                 {
                                     MainForm.comPort.Write(Send_buf, 0, 7);
                                 }
                                 catch
                                 {
                                     MessageBox.Show("串口有误，请检查", "错误");
                                 }
                                 T1.Enabled = false;
                                 T1.Interval = 2000;
                                 T1.Enabled = true;
                             }
                         }
                         RM350_0XFE_XX = 0x00;
                         Send_buf[1] = 0x07;
                     }
                     break;
             }
         }*/

        /*private void btn350Stop_Click(object sender, EventArgs e)
        {
            T12.Enabled = false;
            flag1 = 1;
            flag2 = 1;
            flag3 = 1;
            adjust_Rnum = 0;
            adjust_Gnum = 0;
            adjust_Bnum = 0;
            adjust_l = 0;
            adjust_x = 0;
            adjust_y = 0;
        }*/

        /*private void btnAutogamma350_Click(object sender, EventArgs e)
        {
            int flag = 1;
            double Lr_d, Lg_d, Lb_d;
            D_lums = new double[27, 3];
            D_lum = new double[27];
            index = 0;
            adjust_Rnum = 0;
            adjust_Gnum = 0;
            adjust_Bnum = 0;
            adjust_l = 0;
            adjust_x = 0;
            adjust_y = 0;

            Button btnTmp = (Button)sender;
            switch (btnTmp.Name)
            {
                case "btnAutogamma350":
                    adjust_class = "btnAutogamma350";
                    break;
                case "btnAutogammas350":
                    adjust_class = "btnAutogammas350";
                    break;
                default:
                    break;
            }

            D_lum[0] = Convert.ToDouble(txt_350_255.Text);
            D_lum[1] = Convert.ToDouble(txt_350_239.Text);
            D_lum[2] = Convert.ToDouble(txt_350_223.Text);
            D_lum[3] = Convert.ToDouble(txt_350_207.Text);
            D_lum[4] = Convert.ToDouble(txt_350_191.Text);
            D_lum[5] = Convert.ToDouble(txt_350_175.Text);
            D_lum[6] = Convert.ToDouble(txt_350_159.Text);
            D_lum[7] = Convert.ToDouble(txt_350_143.Text);
            D_lum[8] = Convert.ToDouble(txt_350_127.Text);
            D_lum[9] = Convert.ToDouble(txt_350_111.Text);
            D_lum[10] = Convert.ToDouble(txt_350_95.Text);
            D_lum[11] = Convert.ToDouble(txt_350_79.Text);
            D_lum[12] = Convert.ToDouble(txt_350_63.Text);
            D_lum[13] = Convert.ToDouble(txt_350_55.Text);
            D_lum[14] = Convert.ToDouble(txt_350_47.Text);
            D_lum[15] = Convert.ToDouble(txt_350_39.Text);
            D_lum[16] = Convert.ToDouble(txt_350_35.Text);
            D_lum[17] = Convert.ToDouble(txt_350_31.Text);
            D_lum[18] = Convert.ToDouble(txt_350_27.Text);
            D_lum[19] = Convert.ToDouble(txt_350_23.Text);
            D_lum[20] = Convert.ToDouble(txt_350_19.Text);
            D_lum[21] = Convert.ToDouble(txt_350_15.Text);
            D_lum[22] = Convert.ToDouble(txt_350_11.Text);
            D_lum[23] = Convert.ToDouble(txt_350_7.Text);
            D_lum[24] = Convert.ToDouble(txt_350_3.Text);
            D_lum[25] = Convert.ToDouble(txt_350_2.Text);
            D_lum[26] = Convert.ToDouble(txt_350_1.Text);
            D_x = Convert.ToDouble(txt_350_x.Text);
            D_y = Convert.ToDouble(txt_350_y.Text);
            Lr_d = R_y * ((D_y - G_y) * (B_x - D_x) + (D_x - G_x) * (D_y - B_y)) / B_y / ((D_y - G_y) * (D_x - R_x) + (D_x - G_x) * (R_y - D_y));
            Lb_d = 1.0;
            Lg_d = G_y * ((D_y - R_y) * (B_x - D_x) + (D_x - R_x) * (D_y - B_y)) / B_y / ((D_y - R_y) * (D_x - G_x) + (D_x - R_x) * (G_y - D_y));

            for (int i = 0; i < 27; i++)
            {
                D_lums[i, 0] = D_lum[i] * Lr_d / (Lr_d + Lg_d + Lb_d);
                D_lums[i, 1] = D_lum[i] * Lg_d / (Lr_d + Lg_d + Lb_d);
                D_lums[i, 2] = D_lum[i] * Lb_d / (Lr_d + Lg_d + Lb_d);
            }

            //if (IC_comboBox.SelectedIndex == Setting.IC_Type.RM69350)//69350
            {
                mygamma_r = GAMMAs.RM350_Gamma_r;
                mygamma_g = GAMMAs.RM350_Gamma_g;
                mygamma_b = GAMMAs.RM350_Gamma_b;
            }


            if (adjust_class == "btnAutogammas350")
            {
                R69350_Reg_Addr.Text = "FE";
                R69350_Reg_Data.Text = "51";
                RM350_Others_Click(RM69350_Reg_W, e);
            }
            if (adjust_class == "btnAutogamma350")
            {
                string strtmp = null;
                FileStream fs;
                if (adjust_num == 0 || adjust_num > 5)
                {
                    if (adjust_num > 5)
                    {
                        fs = new FileStream("../Base_gamma_350.csv", FileMode.Open, FileAccess.Read);
                    }
                    else
                    {
                        fs = new FileStream("../Base_gamma_350.csv", FileMode.Open, FileAccess.Read);//Init_gamma_195
                        adjust_num++;
                    }
                    StreamReader streamReader = new StreamReader(fs, Encoding.GetEncoding("GBK"));
                    streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
                    string strLine = streamReader.ReadLine();
                    //循环读取文本信息
                    while (!string.IsNullOrEmpty(strLine))
                    {
                        strtmp = strtmp + strLine + ",";
                        strLine = streamReader.ReadLine(); //循环读取下一行
                    }
                    fs.Close(); //关闭流
                    streamReader.Close();
                    string[] arrtmp = strtmp.Split(new Char[] { ',' });
                    VTDR6100_R0.Text = arrtmp[1].ToString(); VTDR6100_G0.Text = arrtmp[3].ToString(); VTDR6100_B0.Text = arrtmp[5].ToString();
                    VTDR6100_R1.Text = arrtmp[7].ToString(); VTDR6100_G1.Text = arrtmp[9].ToString(); VTDR6100_B1.Text = arrtmp[11].ToString();
                    VTDR6100_R3.Text = arrtmp[13].ToString(); VTDR6100_G3.Text = arrtmp[15].ToString(); VTDR6100_B3.Text = arrtmp[17].ToString();
                    VTDR6100_R5.Text = arrtmp[19].ToString(); VTDR6100_G5.Text = arrtmp[21].ToString(); VTDR6100_B5.Text = arrtmp[23].ToString();
                    VTDR6100_R7.Text = arrtmp[25].ToString(); VTDR6100_G7.Text = arrtmp[27].ToString(); VTDR6100_B7.Text = arrtmp[29].ToString();
                    VTDR6100_R11.Text = arrtmp[31].ToString(); VTDR6100_G11.Text = arrtmp[33].ToString(); VTDR6100_B11.Text = arrtmp[35].ToString();
                    VTDR6100_R15.Text = arrtmp[37].ToString(); VTDR6100_G15.Text = arrtmp[39].ToString(); VTDR6100_B15.Text = arrtmp[41].ToString();
                    VTDR6100_R19.Text = arrtmp[43].ToString(); VTDR6100_G19.Text = arrtmp[45].ToString(); VTDR6100_B19.Text = arrtmp[47].ToString();
                    VTDR6100_R23.Text = arrtmp[49].ToString(); VTDR6100_G23.Text = arrtmp[51].ToString(); VTDR6100_B23.Text = arrtmp[53].ToString();
                    VTDR6100_R27.Text = arrtmp[55].ToString(); VTDR6100_G27.Text = arrtmp[57].ToString(); VTDR6100_B27.Text = arrtmp[59].ToString();
                    VTDR6100_R31.Text = arrtmp[61].ToString(); VTDR6100_G31.Text = arrtmp[63].ToString(); VTDR6100_B31.Text = arrtmp[65].ToString();
                    VTDR6100_R35.Text = arrtmp[67].ToString(); VTDR6100_G35.Text = arrtmp[69].ToString(); VTDR6100_B35.Text = arrtmp[71].ToString();
                    VTDR6100_R39.Text = arrtmp[73].ToString(); VTDR6100_G39.Text = arrtmp[75].ToString(); VTDR6100_B39.Text = arrtmp[77].ToString();
                    VTDR6100_R47.Text = arrtmp[79].ToString(); VTDR6100_G47.Text = arrtmp[81].ToString(); VTDR6100_B47.Text = arrtmp[83].ToString();
                    VTDR6100_R55.Text = arrtmp[85].ToString(); VTDR6100_G55.Text = arrtmp[87].ToString(); VTDR6100_B55.Text = arrtmp[89].ToString();
                    VTDR6100_R63.Text = arrtmp[91].ToString(); VTDR6100_G63.Text = arrtmp[93].ToString(); VTDR6100_B63.Text = arrtmp[95].ToString();
                    VTDR6100_R71.Text = arrtmp[97].ToString(); VTDR6100_G71.Text = arrtmp[99].ToString(); VTDR6100_B71.Text = arrtmp[101].ToString();
                    VTDR6100_R79.Text = arrtmp[103].ToString(); VTDR6100_G79.Text = arrtmp[105].ToString(); VTDR6100_B79.Text = arrtmp[107].ToString();
                    VTDR6100_R95.Text = arrtmp[109].ToString(); VTDR6100_G95.Text = arrtmp[111].ToString(); VTDR6100_B95.Text = arrtmp[113].ToString();
                    VTDR6100_R111.Text = arrtmp[115].ToString(); VTDR6100_G111.Text = arrtmp[117].ToString(); VTDR6100_B111.Text = arrtmp[119].ToString();
                    VTDR6100_R127.Text = arrtmp[121].ToString(); VTDR6100_G127.Text = arrtmp[123].ToString(); VTDR6100_B127.Text = arrtmp[125].ToString();
                    VTDR6100_R159.Text = arrtmp[127].ToString(); VTDR6100_G159.Text = arrtmp[129].ToString(); VTDR6100_B159.Text = arrtmp[131].ToString();
                    VTDR6100_R191.Text = arrtmp[133].ToString(); VTDR6100_G191.Text = arrtmp[135].ToString(); VTDR6100_B191.Text = arrtmp[137].ToString();
                    VTDR6100_R223.Text = arrtmp[139].ToString(); VTDR6100_G223.Text = arrtmp[141].ToString(); VTDR6100_B223.Text = arrtmp[143].ToString();
                    VTDR6100_R255.Text = arrtmp[145].ToString(); VTDR6100_G255.Text = arrtmp[147].ToString(); VTDR6100_B255.Text = arrtmp[149].ToString();
                    rm350_R223.Text = arrtmp[151].ToString(); rm350_G223.Text = arrtmp[153].ToString(); rm350_B223.Text = arrtmp[155].ToString();
                    rm350_R239.Text = arrtmp[157].ToString(); rm350_G239.Text = arrtmp[159].ToString(); rm350_B239.Text = arrtmp[161].ToString();
                    rm350_R255.Text = arrtmp[163].ToString(); rm350_G255.Text = arrtmp[165].ToString(); rm350_B255.Text = arrtmp[167].ToString();


                    RM350_Gamma_Click(VTDR6100_GammaW_Red, e);//调用寄存器写函数，把255阶R-gamma写入寄存器中。
                    RM350_Gamma_Click(VTDR6100_GammaW_Green, e);//调用寄存器写函数，把255阶G-gamma写入寄存器中。
                    RM350_Gamma_Click(VTDR6100_GammaW_Blue, e);//调用寄存器写函数，把255阶B-gamma写入寄存器中。
                }
                else
                {
                    tmp_gamma_350[3] += Convert.ToInt32(VTDR6100_R5.Value); tmp_gamma_350[4] += Convert.ToInt32(VTDR6100_G5.Value); tmp_gamma_350[5] += Convert.ToInt32(VTDR6100_B5.Value);//把gamma数据都加到临时数组上
                    tmp_gamma_350[6] += Convert.ToInt32(VTDR6100_R7.Value); tmp_gamma_350[7] += Convert.ToInt32(VTDR6100_G7.Value); tmp_gamma_350[8] += Convert.ToInt32(VTDR6100_B7.Value);
                    tmp_gamma_350[9] += Convert.ToInt32(VTDR6100_R11.Value); tmp_gamma_350[10] += Convert.ToInt32(VTDR6100_G11.Value); tmp_gamma_350[11] += Convert.ToInt32(VTDR6100_B11.Value);
                    tmp_gamma_350[12] += Convert.ToInt32(VTDR6100_R15.Value); tmp_gamma_350[13] += Convert.ToInt32(VTDR6100_G15.Value); tmp_gamma_350[14] += Convert.ToInt32(VTDR6100_B15.Value);
                    tmp_gamma_350[15] += Convert.ToInt32(VTDR6100_R19.Value); tmp_gamma_350[16] += Convert.ToInt32(VTDR6100_G19.Value); tmp_gamma_350[17] += Convert.ToInt32(VTDR6100_B19.Value);
                    tmp_gamma_350[18] += Convert.ToInt32(VTDR6100_R23.Value); tmp_gamma_350[19] += Convert.ToInt32(VTDR6100_G23.Value); tmp_gamma_350[20] += Convert.ToInt32(VTDR6100_B23.Value);
                    tmp_gamma_350[21] += Convert.ToInt32(VTDR6100_R27.Value); tmp_gamma_350[22] += Convert.ToInt32(VTDR6100_G27.Value); tmp_gamma_350[23] += Convert.ToInt32(VTDR6100_B27.Value);
                    tmp_gamma_350[24] += Convert.ToInt32(VTDR6100_R31.Value); tmp_gamma_350[25] += Convert.ToInt32(VTDR6100_G31.Value); tmp_gamma_350[26] += Convert.ToInt32(VTDR6100_B31.Value);
                    tmp_gamma_350[27] += Convert.ToInt32(VTDR6100_R35.Value); tmp_gamma_350[28] += Convert.ToInt32(VTDR6100_G35.Value); tmp_gamma_350[29] += Convert.ToInt32(VTDR6100_B35.Value);
                    tmp_gamma_350[30] += Convert.ToInt32(VTDR6100_R39.Value); tmp_gamma_350[31] += Convert.ToInt32(VTDR6100_G39.Value); tmp_gamma_350[32] += Convert.ToInt32(VTDR6100_B39.Value);
                    tmp_gamma_350[33] += Convert.ToInt32(VTDR6100_R47.Value); tmp_gamma_350[34] += Convert.ToInt32(VTDR6100_G47.Value); tmp_gamma_350[35] += Convert.ToInt32(VTDR6100_B47.Value);
                    tmp_gamma_350[36] += Convert.ToInt32(VTDR6100_R55.Value); tmp_gamma_350[37] += Convert.ToInt32(VTDR6100_G55.Value); tmp_gamma_350[38] += Convert.ToInt32(VTDR6100_B55.Value);
                    tmp_gamma_350[39] += Convert.ToInt32(VTDR6100_R63.Value); tmp_gamma_350[40] += Convert.ToInt32(VTDR6100_G63.Value); tmp_gamma_350[41] += Convert.ToInt32(VTDR6100_B63.Value);
                    tmp_gamma_350[42] += Convert.ToInt32(VTDR6100_R71.Value); tmp_gamma_350[43] += Convert.ToInt32(VTDR6100_G71.Value); tmp_gamma_350[44] += Convert.ToInt32(VTDR6100_B71.Value);
                    tmp_gamma_350[45] += Convert.ToInt32(VTDR6100_R79.Value); tmp_gamma_350[46] += Convert.ToInt32(VTDR6100_G79.Value); tmp_gamma_350[47] += Convert.ToInt32(VTDR6100_B79.Value);
                    tmp_gamma_350[48] += Convert.ToInt32(VTDR6100_R95.Value); tmp_gamma_350[49] += Convert.ToInt32(VTDR6100_G95.Value); tmp_gamma_350[50] += Convert.ToInt32(VTDR6100_B95.Value);
                    tmp_gamma_350[51] += Convert.ToInt32(VTDR6100_R111.Value); tmp_gamma_350[52] += Convert.ToInt32(VTDR6100_G111.Value); tmp_gamma_350[53] += Convert.ToInt32(VTDR6100_B111.Value);
                    tmp_gamma_350[54] += Convert.ToInt32(VTDR6100_R127.Value); tmp_gamma_350[55] += Convert.ToInt32(VTDR6100_G127.Value); tmp_gamma_350[56] += Convert.ToInt32(VTDR6100_B127.Value);
                    tmp_gamma_350[57] += Convert.ToInt32(VTDR6100_R159.Value); tmp_gamma_350[58] += Convert.ToInt32(VTDR6100_G159.Value); tmp_gamma_350[59] += Convert.ToInt32(VTDR6100_B159.Value);
                    tmp_gamma_350[60] += Convert.ToInt32(VTDR6100_R191.Value); tmp_gamma_350[61] += Convert.ToInt32(VTDR6100_G191.Value); tmp_gamma_350[62] += Convert.ToInt32(VTDR6100_B191.Value);
                    tmp_gamma_350[63] += Convert.ToInt32(VTDR6100_R223.Value); tmp_gamma_350[64] += Convert.ToInt32(VTDR6100_G223.Value); tmp_gamma_350[65] += Convert.ToInt32(VTDR6100_B223.Value);
                    tmp_gamma_350[66] += Convert.ToInt32(VTDR6100_R255.Value); tmp_gamma_350[67] += Convert.ToInt32(VTDR6100_G255.Value); tmp_gamma_350[68] += Convert.ToInt32(VTDR6100_B255.Value);
                    tmp_gamma_350[69] += Convert.ToInt32(rm350_R223.Value); tmp_gamma_350[70] += Convert.ToInt32(rm350_G223.Value); tmp_gamma_350[71] += Convert.ToInt32(rm350_B223.Value);
                    tmp_gamma_350[72] += Convert.ToInt32(rm350_R255.Value); tmp_gamma_350[73] += Convert.ToInt32(rm350_G255.Value); tmp_gamma_350[74] += Convert.ToInt32(rm350_B255.Value);

                    adjust_num++;

                    if (adjust_num == 6)
                    {
                        VTDR6100_R5.Value = tmp_gamma_350[3] / 5; VTDR6100_G5.Value = tmp_gamma_350[4] / 5; VTDR6100_B5.Value = tmp_gamma_350[5] / 5;
                        VTDR6100_R7.Value = tmp_gamma_350[6] / 5; VTDR6100_G7.Value = tmp_gamma_350[7] / 5; VTDR6100_B7.Value = tmp_gamma_350[8] / 5;
                        VTDR6100_R11.Value = tmp_gamma_350[9] / 5; VTDR6100_G11.Value = tmp_gamma_350[10] / 5; VTDR6100_B11.Value = tmp_gamma_350[11] / 5;
                        VTDR6100_R15.Value = tmp_gamma_350[12] / 5; VTDR6100_G15.Value = tmp_gamma_350[13] / 5; VTDR6100_B15.Value = tmp_gamma_350[14] / 5;
                        VTDR6100_R19.Value = tmp_gamma_350[15] / 5; VTDR6100_G19.Value = tmp_gamma_350[16] / 5; VTDR6100_B19.Value = tmp_gamma_350[17] / 5;
                        VTDR6100_R23.Value = tmp_gamma_350[18] / 5; VTDR6100_G23.Value = tmp_gamma_350[19] / 5; VTDR6100_B23.Value = tmp_gamma_350[20] / 5;
                        VTDR6100_R27.Value = tmp_gamma_350[21] / 5; VTDR6100_G27.Value = tmp_gamma_350[22] / 5; VTDR6100_B27.Value = tmp_gamma_350[23] / 5;
                        VTDR6100_R31.Value = tmp_gamma_350[24] / 5; VTDR6100_G31.Value = tmp_gamma_350[25] / 5; VTDR6100_B31.Value = tmp_gamma_350[26] / 5;
                        VTDR6100_R35.Value = tmp_gamma_350[27] / 5; VTDR6100_G35.Value = tmp_gamma_350[28] / 5; VTDR6100_B35.Value = tmp_gamma_350[29] / 5;
                        VTDR6100_R39.Value = tmp_gamma_350[30] / 5; VTDR6100_G39.Value = tmp_gamma_350[31] / 5; VTDR6100_B39.Value = tmp_gamma_350[32] / 5;
                        VTDR6100_R47.Value = tmp_gamma_350[33] / 5; VTDR6100_G47.Value = tmp_gamma_350[34] / 5; VTDR6100_B47.Value = tmp_gamma_350[35] / 5;
                        VTDR6100_R55.Value = tmp_gamma_350[36] / 5; VTDR6100_G55.Value = tmp_gamma_350[37] / 5; VTDR6100_B55.Value = tmp_gamma_350[38] / 5;
                        VTDR6100_R63.Value = tmp_gamma_350[39] / 5; VTDR6100_G63.Value = tmp_gamma_350[40] / 5; VTDR6100_B63.Value = tmp_gamma_350[41] / 5;
                        VTDR6100_R71.Value = tmp_gamma_350[42] / 5; VTDR6100_G71.Value = tmp_gamma_350[43] / 5; VTDR6100_B71.Value = tmp_gamma_350[44] / 5;
                        VTDR6100_R79.Value = tmp_gamma_350[45] / 5; VTDR6100_G79.Value = tmp_gamma_350[46] / 5; VTDR6100_B79.Value = tmp_gamma_350[47] / 5;
                        VTDR6100_R95.Value = tmp_gamma_350[48] / 5; VTDR6100_G95.Value = tmp_gamma_350[49] / 5; VTDR6100_B95.Value = tmp_gamma_350[50] / 5;
                        VTDR6100_R111.Value = tmp_gamma_350[51] / 5; VTDR6100_G111.Value = tmp_gamma_350[52] / 5; VTDR6100_B111.Value = tmp_gamma_350[53] / 5;
                        VTDR6100_R127.Value = tmp_gamma_350[54] / 5; VTDR6100_G127.Value = tmp_gamma_350[55] / 5; VTDR6100_B127.Value = tmp_gamma_350[56] / 5;
                        VTDR6100_R159.Value = tmp_gamma_350[57] / 5; VTDR6100_G159.Value = tmp_gamma_350[58] / 5; VTDR6100_B159.Value = tmp_gamma_350[59] / 5;
                        VTDR6100_R191.Value = tmp_gamma_350[60] / 5; VTDR6100_G191.Value = tmp_gamma_350[61] / 5; VTDR6100_B191.Value = tmp_gamma_350[62] / 5;
                        VTDR6100_R223.Value = tmp_gamma_350[63] / 5; VTDR6100_G223.Value = tmp_gamma_350[64] / 5; VTDR6100_B223.Value = tmp_gamma_350[65] / 5;
                        VTDR6100_R255.Value = tmp_gamma_350[66] / 5; VTDR6100_G255.Value = tmp_gamma_350[67] / 5; VTDR6100_B255.Value = tmp_gamma_350[68] / 5;
                        rm350_R223.Value = tmp_gamma_350[69] / 5; rm350_G223.Value = tmp_gamma_350[70] / 5; rm350_B223.Value = tmp_gamma_350[71] / 5;
                        rm350_R255.Value = tmp_gamma_350[72] / 5; rm350_G255.Value = tmp_gamma_350[73] / 5; rm350_B255.Value = tmp_gamma_350[74] / 5;



                        fs = new FileStream("../Base_gamma_350.csv", FileMode.OpenOrCreate, FileAccess.Write);
                        fs.Close();
                        StreamWriter sw = new StreamWriter(fs.Name, false, Encoding.UTF8);
                        strtmp = strtmp + "R0," + VTDR6100_R0.Text + "," + "G0," + VTDR6100_G0.Text + "," + "B0," + VTDR6100_B0.Text + "\r\n";
                        strtmp = strtmp + "R3," + VTDR6100_R5.Text + "," + "G3," + VTDR6100_G5.Text + "," + "B3," + VTDR6100_B5.Text + "\r\n";
                        strtmp = strtmp + "R7," + VTDR6100_R7.Text + "," + "G7," + VTDR6100_G7.Text + "," + "B7," + VTDR6100_B7.Text + "\r\n";
                        strtmp = strtmp + "R11," + VTDR6100_R11.Text + "," + "G11," + VTDR6100_G11.Text + "," + "B11," + VTDR6100_B11.Text + "\r\n";
                        strtmp = strtmp + "R15," + VTDR6100_R15.Text + "," + "G15," + VTDR6100_G15.Text + "," + "B15," + VTDR6100_B15.Text + "\r\n";
                        strtmp = strtmp + "R19," + VTDR6100_R19.Text + "," + "G19," + VTDR6100_G19.Text + "," + "B19," + VTDR6100_B19.Text + "\r\n";
                        strtmp = strtmp + "R23," + VTDR6100_R23.Text + "," + "G23," + VTDR6100_G23.Text + "," + "B23," + VTDR6100_B23.Text + "\r\n";
                        strtmp = strtmp + "R27," + VTDR6100_R27.Text + "," + "G27," + VTDR6100_G27.Text + "," + "B27," + VTDR6100_B27.Text + "\r\n";
                        strtmp = strtmp + "R31," + VTDR6100_R31.Text + "," + "G31," + VTDR6100_G31.Text + "," + "B31," + VTDR6100_B31.Text + "\r\n";
                        strtmp = strtmp + "R35," + VTDR6100_R35.Text + "," + "G35," + VTDR6100_G35.Text + "," + "B35," + VTDR6100_B35.Text + "\r\n";
                        strtmp = strtmp + "R39," + VTDR6100_R39.Text + "," + "G39," + VTDR6100_G39.Text + "," + "B39," + VTDR6100_B39.Text + "\r\n";
                        strtmp = strtmp + "R47," + VTDR6100_R47.Text + "," + "G47," + VTDR6100_G47.Text + "," + "B47," + VTDR6100_B47.Text + "\r\n";
                        strtmp = strtmp + "R55," + VTDR6100_R55.Text + "," + "G55," + VTDR6100_G55.Text + "," + "B55," + VTDR6100_B55.Text + "\r\n";
                        strtmp = strtmp + "R63," + VTDR6100_R63.Text + "," + "G63," + VTDR6100_G63.Text + "," + "B63," + VTDR6100_B63.Text + "\r\n";
                        strtmp = strtmp + "R79," + VTDR6100_R71.Text + "," + "G79," + VTDR6100_G71.Text + "," + "B79," + VTDR6100_B71.Text + "\r\n";
                        strtmp = strtmp + "R95," + VTDR6100_R79.Text + "," + "G95," + VTDR6100_G79.Text + "," + "B95," + VTDR6100_B79.Text + "\r\n";
                        strtmp = strtmp + "R111," + VTDR6100_R95.Text + "," + "G111," + VTDR6100_G95.Text + "," + "B111," + VTDR6100_B95.Text + "\r\n";
                        strtmp = strtmp + "R127," + VTDR6100_R111.Text + "," + "G127," + VTDR6100_G111.Text + "," + "B127," + VTDR6100_B111.Text + "\r\n";
                        strtmp = strtmp + "R143," + VTDR6100_R127.Text + "," + "G143," + VTDR6100_G127.Text + "," + "B143," + VTDR6100_B127.Text + "\r\n";
                        strtmp = strtmp + "R159," + VTDR6100_R159.Text + "," + "G159," + VTDR6100_G159.Text + "," + "B159," + VTDR6100_B159.Text + "\r\n";
                        strtmp = strtmp + "R175," + VTDR6100_R191.Text + "," + "G175," + VTDR6100_G191.Text + "," + "B175," + VTDR6100_B191.Text + "\r\n";
                        strtmp = strtmp + "R191," + VTDR6100_R223.Text + "," + "G191," + VTDR6100_G223.Text + "," + "B191," + VTDR6100_B223.Text + "\r\n";
                        strtmp = strtmp + "R207," + VTDR6100_R255.Text + "," + "G207," + VTDR6100_G255.Text + "," + "B207," + VTDR6100_B255.Text + "\r\n";
                        strtmp = strtmp + "R223," + rm350_R223.Text + "," + "G223," + rm350_G223.Text + "," + "B223," + rm350_B223.Text + "\r\n";
                        strtmp = strtmp + "R255," + rm350_R255.Text + "," + "G255," + rm350_G255.Text + "," + "B255," + rm350_B255.Text + "\r\n";

                        sw.WriteLine(strtmp);
                        sw.Dispose(); //释放资源
                        sw.Close(); //关闭数据流        
                    }
                }
            }

            switch (flag)
            {
                case 1://寄存器值与亮度正比
                    {
                        lum_off = Convert.ToDouble(txt_350_loff.Text);
                        x_off = Convert.ToDouble(txt_350_xoff.Text);
                        y_off = Convert.ToDouble(txt_350_yoff.Text);
                        MainForm.LCD_Cfg_Click(btnwhite, e);
                        //OLED_Show_Click(btnPatternW, null);
                        T12.Enabled = true;
                    }
                    break;
                case 2://寄存器值与亮度反比
                    break;
                default:
                    break;
            }
        }

        void auto_gamma_write(UInt16 addr, UInt16 datar, UInt16 addg, UInt16 datag, UInt16 addb, UInt16 Datab)//一组gamma写入
        {
            Send_buf = new byte[17];
            Setting.TempRecord.cmdLen = 17;

            if ((datar < 0x000f) || (datag < 0x000f) || (Datab < 0x000f) || (datar > 0x0ff0) || (datag > 0x0ff0) || (Datab > 0x0ff0))
            {
                //T5.Enabled = false;
                //T6.Enabled = false;
                //T7.Enabled = false;
                //T8.Enabled = false;
                T12.Enabled = false;
                //T13.Enabled = false;
                //T14.Enabled = false;
                //T15.Enabled = false;
                flag1 = 1;
                flag2 = 1;
                flag3 = 1;
                adjust_Rnum = 0;
                adjust_Gnum = 0;
                adjust_Bnum = 0;
                adjust_l = 0;
                adjust_x = 0;
                adjust_y = 0;
                MessageBox.Show("数值超出界限，已停止gamma调试", "提示");
            }

            switch (MainForm.IC_comboBox.SelectedIndex)
            {
                case 0:
                    Send_buf[0] = 0x09;//195
                    break;
                case 1:
                    Send_buf[0] = 0x08;//120
                    break;
                case 2:
                    Send_buf[0] = 0x0E;//160
                    break;
                case 3:
                    Send_buf[0] = 0x1E;//162
                    break;
                case 4:
                    Send_buf[0] = 0x19;//295
                    break;
                case 5:
                    Send_buf[0] = 0x29;//198
                    break;
                case 8:
                    Send_buf[0] = 0x2C;//300
                    break;
                case 10:
                    Send_buf[0] = 0x2e;//298
                    break;
                case 11:
                    Send_buf[0] = 0x3C;//350
                    break;
                case 12:
                    Send_buf[0] = 0x3D;//010
                    break;
                case 13:
                    Send_buf[0] = 0x30;//R66455
                    break;
                default:
                    break;
            }
            Send_buf[1] = 0xDD;
            Send_buf[2] = 12;
            Send_buf[3] = Convert.ToByte(addr >> 8);
            Send_buf[4] = Convert.ToByte(datar >> 8);
            Send_buf[5] = Convert.ToByte(addr & 0xff);
            Send_buf[6] = Convert.ToByte(datar & 0xff);
            Send_buf[7] = Convert.ToByte(addg >> 8);
            Send_buf[8] = Convert.ToByte(datag >> 8);
            Send_buf[9] = Convert.ToByte(addg & 0xff);
            Send_buf[10] = Convert.ToByte(datag & 0xff);
            Send_buf[11] = Convert.ToByte(addb >> 8);
            Send_buf[12] = Convert.ToByte(Datab >> 8);
            Send_buf[13] = Convert.ToByte(addb & 0xff);
            Send_buf[14] = Convert.ToByte(Datab & 0xff);
            CRCData.CalculateCrc16(Send_buf, out Send_buf[15], out Send_buf[16]);
            try
            {
                MainForm.comPort.Write(Send_buf, 0, 17);
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
        }*/

        private void VTDR6100_GAMMA_Click(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;

            if (frm_new_vtdr6110 == 0)
            {
                button3_Click(button3, e);
                System.Threading.Thread.Sleep(100);
                frm_new_vtdr6110 = 1;
            }


            Send_buf = new byte[57];
            Setting.TempRecord.cmdLen = 57;
            Send_buf[2] = 52;
            Send_buf[3] = 0;
            Send_buf[0] = 0x4D; //VTDR6100


            switch (btnTmp.Name)
            {
                case "VTDR6100_GammaR_Red":
                    {

                        Send_buf[1] = 0x09;                             //读Gamma
                        Send_buf[3] = 0x00;                            //红色red
                        Send_buf[4] = 0x00;
                        Setting.TempRecord.VTDR6100CmdType = 0x03;       //      1
                    }
                    break;


                case "VTDR6100_GammaR_Green":
                    {

                        Send_buf[1] = 0x09;                         //  读Gamma
                        Send_buf[3] = 0x42;                        //绿色 green
                        Send_buf[4] = 0x00;
                        Setting.TempRecord.VTDR6100CmdType = 0x04;   //      4

                    }
                    break;

                case "VTDR6100_GammaR_Blue": //              9
                    {

                        Send_buf[1] = 0x09;                         //   读Gamma
                        Send_buf[3] = 0x81;                        //   blue  
                        Send_buf[4] = 0x00;
                        Setting.TempRecord.VTDR6100CmdType = 0x05;   //      5

                    }
                    break;

                //--------------------------------------
                case "VTDR6100_GammaW_Red":
                    {
                        Send_buf[1] = 0x08;                       //写Gamma
                        Send_buf[3] = 0x00;                       //红色1
                        Send_buf[4] = 0x00;

                        Send_buf[5] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R0.Value.ToString()) >> 8);
                        Send_buf[6] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R0.Value.ToString())) & 0xff);
                        Send_buf[7] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R1.Value.ToString()) >> 8);
                        Send_buf[8] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R1.Value.ToString())) & 0xff);
                        Send_buf[9] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R3.Value.ToString()) >> 8);
                        Send_buf[10] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R3.Value.ToString())) & 0xff);
                        Send_buf[11] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R5.Value.ToString()) >> 8);
                        Send_buf[12] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R5.Value.ToString())) & 0xff);
                        Send_buf[13] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R7.Value.ToString()) >> 8);
                        Send_buf[14] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R7.Value.ToString())) & 0xff);
                        Send_buf[15] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R11.Value.ToString()) >> 8);
                        Send_buf[16] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R11.Value.ToString())) & 0xff);
                        Send_buf[17] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R15.Value.ToString()) >> 8);
                        Send_buf[18] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R15.Value.ToString())) & 0xff);
                        Send_buf[19] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R19.Value.ToString()) >> 8);
                        Send_buf[20] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R19.Value.ToString())) & 0xff);

                        Send_buf[21] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R23.Value.ToString()) >> 8);
                        Send_buf[22] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R23.Value.ToString())) & 0xff);
                        Send_buf[23] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R27.Value.ToString()) >> 8);
                        Send_buf[24] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R27.Value.ToString())) & 0xff);
                        Send_buf[25] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R31.Value.ToString()) >> 8);
                        Send_buf[26] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R31.Value.ToString())) & 0xff);
                        Send_buf[27] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R35.Value.ToString()) >> 8);
                        Send_buf[28] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R35.Value.ToString())) & 0xff);
                        Send_buf[29] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R39.Value.ToString()) >> 8);
                        Send_buf[30] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R39.Value.ToString())) & 0xff);
                        Send_buf[31] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R47.Value.ToString()) >> 8);
                        Send_buf[32] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R47.Value.ToString())) & 0xff);
                        Send_buf[33] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R55.Value.ToString()) >> 8);
                        Send_buf[34] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R55.Value.ToString())) & 0xff);
                        Send_buf[35] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R63.Value.ToString()) >> 8);
                        Send_buf[36] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R63.Value.ToString())) & 0xff);

                        Send_buf[37] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R71.Value.ToString()) >> 8);
                        Send_buf[38] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R71.Value.ToString())) & 0xff);
                        Send_buf[39] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R79.Value.ToString()) >> 8);
                        Send_buf[40] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R79.Value.ToString())) & 0xff);
                        Send_buf[41] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R95.Value.ToString()) >> 8);
                        Send_buf[42] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R95.Value.ToString())) & 0xff);
                        Send_buf[43] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R111.Value.ToString()) >> 8);
                        Send_buf[44] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R111.Value.ToString())) & 0xff);
                        Send_buf[45] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R127.Value.ToString()) >> 8);
                        Send_buf[46] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R127.Value.ToString())) & 0xff);
                        Send_buf[47] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R159.Value.ToString()) >> 8);
                        Send_buf[48] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R159.Value.ToString())) & 0xff);
                        Send_buf[49] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R191.Value.ToString()) >> 8);
                        Send_buf[50] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R191.Value.ToString())) & 0xff);
                        Send_buf[51] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R223.Value.ToString()) >> 8);
                        Send_buf[52] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R223.Value.ToString())) & 0xff);

                        Send_buf[53] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R255.Value.ToString()) >> 8);
                        Send_buf[54] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R255.Value.ToString())) & 0xff);


                    }
                    break;

                case "VTDR6100_GammaW_Green":
                    {
                        Send_buf[1] = 0x08;
                        Send_buf[3] = 0x42;                       //绿色1
                        Send_buf[4] = 0x04;

                        Send_buf[5] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G0.Value.ToString()) >> 8);
                        Send_buf[6] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G0.Value.ToString())) & 0xff);
                        Send_buf[7] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G1.Value.ToString()) >> 8);
                        Send_buf[8] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G1.Value.ToString())) & 0xff);
                        Send_buf[9] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G3.Value.ToString()) >> 8);
                        Send_buf[10] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G3.Value.ToString())) & 0xff);
                        Send_buf[11] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G5.Value.ToString()) >> 8);
                        Send_buf[12] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G5.Value.ToString())) & 0xff);
                        Send_buf[13] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G7.Value.ToString()) >> 8);
                        Send_buf[14] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G7.Value.ToString())) & 0xff);
                        Send_buf[15] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G11.Value.ToString()) >> 8);
                        Send_buf[16] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G11.Value.ToString())) & 0xff);
                        Send_buf[17] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G15.Value.ToString()) >> 8);
                        Send_buf[18] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G15.Value.ToString())) & 0xff);
                        Send_buf[19] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G19.Value.ToString()) >> 8);
                        Send_buf[20] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G19.Value.ToString())) & 0xff);

                        Send_buf[21] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G23.Value.ToString()) >> 8);
                        Send_buf[22] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G23.Value.ToString())) & 0xff);
                        Send_buf[23] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G27.Value.ToString()) >> 8);
                        Send_buf[24] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G27.Value.ToString())) & 0xff);
                        Send_buf[25] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G31.Value.ToString()) >> 8);
                        Send_buf[26] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G31.Value.ToString())) & 0xff);
                        Send_buf[27] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G35.Value.ToString()) >> 8);
                        Send_buf[28] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G35.Value.ToString())) & 0xff);
                        Send_buf[29] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G39.Value.ToString()) >> 8);
                        Send_buf[30] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G39.Value.ToString())) & 0xff);
                        Send_buf[31] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G47.Value.ToString()) >> 8);
                        Send_buf[32] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G47.Value.ToString())) & 0xff);
                        Send_buf[33] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G55.Value.ToString()) >> 8);
                        Send_buf[34] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G55.Value.ToString())) & 0xff);
                        Send_buf[35] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G63.Value.ToString()) >> 8);
                        Send_buf[36] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G63.Value.ToString())) & 0xff);

                        Send_buf[37] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G71.Value.ToString()) >> 8);
                        Send_buf[38] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G71.Value.ToString())) & 0xff);
                        Send_buf[39] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G79.Value.ToString()) >> 8);
                        Send_buf[40] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G79.Value.ToString())) & 0xff);
                        Send_buf[41] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G95.Value.ToString()) >> 8);
                        Send_buf[42] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G95.Value.ToString())) & 0xff);
                        Send_buf[43] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G111.Value.ToString()) >> 8);
                        Send_buf[44] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G111.Value.ToString())) & 0xff);
                        Send_buf[45] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G127.Value.ToString()) >> 8);
                        Send_buf[46] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G127.Value.ToString())) & 0xff);
                        Send_buf[47] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G159.Value.ToString()) >> 8);
                        Send_buf[48] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G159.Value.ToString())) & 0xff);
                        Send_buf[49] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G191.Value.ToString()) >> 8);
                        Send_buf[50] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G191.Value.ToString())) & 0xff);
                        Send_buf[51] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G223.Value.ToString()) >> 8);
                        Send_buf[52] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G223.Value.ToString())) & 0xff);

                        Send_buf[53] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G255.Value.ToString()) >> 8);
                        Send_buf[54] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G255.Value.ToString())) & 0xff);

                    }
                    break;

                case "VTDR6100_GammaW_Blue":     //      8
                    {
                        Send_buf[1] = 0x08;
                        Send_buf[3] = 0x81;
                        Send_buf[4] = 0x08;

                        Send_buf[5] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B0.Value.ToString()) >> 8);
                        Send_buf[6] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B0.Value.ToString())) & 0xff);
                        Send_buf[7] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B1.Value.ToString()) >> 8);
                        Send_buf[8] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B1.Value.ToString())) & 0xff);
                        Send_buf[9] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B3.Value.ToString()) >> 8);
                        Send_buf[10] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B3.Value.ToString())) & 0xff);
                        Send_buf[11] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B5.Value.ToString()) >> 8);
                        Send_buf[12] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B5.Value.ToString())) & 0xff);
                        Send_buf[13] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B7.Value.ToString()) >> 8);
                        Send_buf[14] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B7.Value.ToString())) & 0xff);
                        Send_buf[15] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B11.Value.ToString()) >> 8);
                        Send_buf[16] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B11.Value.ToString())) & 0xff);
                        Send_buf[17] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B15.Value.ToString()) >> 8);
                        Send_buf[18] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B15.Value.ToString())) & 0xff);
                        Send_buf[19] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B19.Value.ToString()) >> 8);
                        Send_buf[20] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B19.Value.ToString())) & 0xff);

                        Send_buf[21] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B23.Value.ToString()) >> 8);
                        Send_buf[22] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B23.Value.ToString())) & 0xff);
                        Send_buf[23] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B27.Value.ToString()) >> 8);
                        Send_buf[24] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B27.Value.ToString())) & 0xff);
                        Send_buf[25] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B31.Value.ToString()) >> 8);
                        Send_buf[26] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B31.Value.ToString())) & 0xff);
                        Send_buf[27] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B35.Value.ToString()) >> 8);
                        Send_buf[28] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B35.Value.ToString())) & 0xff);
                        Send_buf[29] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B39.Value.ToString()) >> 8);
                        Send_buf[30] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B39.Value.ToString())) & 0xff);
                        Send_buf[31] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B47.Value.ToString()) >> 8);
                        Send_buf[32] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B47.Value.ToString())) & 0xff);
                        Send_buf[33] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B55.Value.ToString()) >> 8);
                        Send_buf[34] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B55.Value.ToString())) & 0xff);
                        Send_buf[35] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B63.Value.ToString()) >> 8);
                        Send_buf[36] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B63.Value.ToString())) & 0xff);

                        Send_buf[37] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B71.Value.ToString()) >> 8);
                        Send_buf[38] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B71.Value.ToString())) & 0xff);
                        Send_buf[39] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B79.Value.ToString()) >> 8);
                        Send_buf[40] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B79.Value.ToString())) & 0xff);
                        Send_buf[41] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B95.Value.ToString()) >> 8);
                        Send_buf[42] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B95.Value.ToString())) & 0xff);
                        Send_buf[43] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B111.Value.ToString()) >> 8);
                        Send_buf[44] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B111.Value.ToString())) & 0xff);
                        Send_buf[45] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B127.Value.ToString()) >> 8);
                        Send_buf[46] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B127.Value.ToString())) & 0xff);
                        Send_buf[47] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B159.Value.ToString()) >> 8);
                        Send_buf[48] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B159.Value.ToString())) & 0xff);
                        Send_buf[49] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B191.Value.ToString()) >> 8);
                        Send_buf[50] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B191.Value.ToString())) & 0xff);
                        Send_buf[51] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B223.Value.ToString()) >> 8);
                        Send_buf[52] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B223.Value.ToString())) & 0xff);

                        Send_buf[53] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B255.Value.ToString()) >> 8);
                        Send_buf[54] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B255.Value.ToString())) & 0xff);

                    }
                    break;

                case "UP_READ_GAMMA":
                    {
                        Send_buf[1] = 0x0A;                       //写Gamma
                        Send_buf[3] = 0x00;                       //红色1
                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(VTDR6100_Gamma_Group.Value.ToString()));

                        Send_buf[5] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R0.Value.ToString()) >> 8);
                        Send_buf[6] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R0.Value.ToString())) & 0xff);
                        Send_buf[7] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R1.Value.ToString()) >> 8);
                        Send_buf[8] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R1.Value.ToString())) & 0xff);
                        Send_buf[9] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R3.Value.ToString()) >> 8);
                        Send_buf[10] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R3.Value.ToString())) & 0xff);
                        Send_buf[11] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R5.Value.ToString()) >> 8);
                        Send_buf[12] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R5.Value.ToString())) & 0xff);
                        Send_buf[13] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R7.Value.ToString()) >> 8);
                        Send_buf[14] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R7.Value.ToString())) & 0xff);
                        Send_buf[15] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R11.Value.ToString()) >> 8);
                        Send_buf[16] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R11.Value.ToString())) & 0xff);
                        Send_buf[17] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R15.Value.ToString()) >> 8);
                        Send_buf[18] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R15.Value.ToString())) & 0xff);
                        Send_buf[19] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R19.Value.ToString()) >> 8);
                        Send_buf[20] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R19.Value.ToString())) & 0xff);

                        Send_buf[21] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R23.Value.ToString()) >> 8);
                        Send_buf[22] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R23.Value.ToString())) & 0xff);
                        Send_buf[23] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R27.Value.ToString()) >> 8);
                        Send_buf[24] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R27.Value.ToString())) & 0xff);
                        Send_buf[25] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R31.Value.ToString()) >> 8);
                        Send_buf[26] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R31.Value.ToString())) & 0xff);
                        Send_buf[27] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R35.Value.ToString()) >> 8);
                        Send_buf[28] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R35.Value.ToString())) & 0xff);
                        Send_buf[29] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R39.Value.ToString()) >> 8);
                        Send_buf[30] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R39.Value.ToString())) & 0xff);
                        Send_buf[31] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R47.Value.ToString()) >> 8);
                        Send_buf[32] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R47.Value.ToString())) & 0xff);
                        Send_buf[33] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R55.Value.ToString()) >> 8);
                        Send_buf[34] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R55.Value.ToString())) & 0xff);
                        Send_buf[35] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R63.Value.ToString()) >> 8);
                        Send_buf[36] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R63.Value.ToString())) & 0xff);

                        Send_buf[37] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R71.Value.ToString()) >> 8);
                        Send_buf[38] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R71.Value.ToString())) & 0xff);
                        Send_buf[39] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R79.Value.ToString()) >> 8);
                        Send_buf[40] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R79.Value.ToString())) & 0xff);
                        Send_buf[41] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R95.Value.ToString()) >> 8);
                        Send_buf[42] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R95.Value.ToString())) & 0xff);
                        Send_buf[43] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R111.Value.ToString()) >> 8);
                        Send_buf[44] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R111.Value.ToString())) & 0xff);
                        Send_buf[45] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R127.Value.ToString()) >> 8);
                        Send_buf[46] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R127.Value.ToString())) & 0xff);
                        Send_buf[47] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R159.Value.ToString()) >> 8);
                        Send_buf[48] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R159.Value.ToString())) & 0xff);
                        Send_buf[49] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R191.Value.ToString()) >> 8);
                        Send_buf[50] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R191.Value.ToString())) & 0xff);
                        Send_buf[51] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R223.Value.ToString()) >> 8);
                        Send_buf[52] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R223.Value.ToString())) & 0xff);

                        Send_buf[53] = Convert.ToByte(Convert.ToUInt16(VTDR6100_R255.Value.ToString()) >> 8);
                        Send_buf[54] = Convert.ToByte((Convert.ToUInt16(VTDR6100_R255.Value.ToString())) & 0xff);


                    }
                    break;

                case "UP_GREEN_GAMMA":
                    {
                        Send_buf[1] = 0x0A;
                        Send_buf[3] = 0x42;                       //绿色1
                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(VTDR6100_Gamma_Group.Value.ToString()));

                        Send_buf[5] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G0.Value.ToString()) >> 8);
                        Send_buf[6] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G0.Value.ToString())) & 0xff);
                        Send_buf[7] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G1.Value.ToString()) >> 8);
                        Send_buf[8] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G1.Value.ToString())) & 0xff);
                        Send_buf[9] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G3.Value.ToString()) >> 8);
                        Send_buf[10] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G3.Value.ToString())) & 0xff);
                        Send_buf[11] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G5.Value.ToString()) >> 8);
                        Send_buf[12] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G5.Value.ToString())) & 0xff);
                        Send_buf[13] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G7.Value.ToString()) >> 8);
                        Send_buf[14] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G7.Value.ToString())) & 0xff);
                        Send_buf[15] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G11.Value.ToString()) >> 8);
                        Send_buf[16] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G11.Value.ToString())) & 0xff);
                        Send_buf[17] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G15.Value.ToString()) >> 8);
                        Send_buf[18] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G15.Value.ToString())) & 0xff);
                        Send_buf[19] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G19.Value.ToString()) >> 8);
                        Send_buf[20] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G19.Value.ToString())) & 0xff);

                        Send_buf[21] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G23.Value.ToString()) >> 8);
                        Send_buf[22] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G23.Value.ToString())) & 0xff);
                        Send_buf[23] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G27.Value.ToString()) >> 8);
                        Send_buf[24] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G27.Value.ToString())) & 0xff);
                        Send_buf[25] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G31.Value.ToString()) >> 8);
                        Send_buf[26] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G31.Value.ToString())) & 0xff);
                        Send_buf[27] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G35.Value.ToString()) >> 8);
                        Send_buf[28] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G35.Value.ToString())) & 0xff);
                        Send_buf[29] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G39.Value.ToString()) >> 8);
                        Send_buf[30] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G39.Value.ToString())) & 0xff);
                        Send_buf[31] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G47.Value.ToString()) >> 8);
                        Send_buf[32] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G47.Value.ToString())) & 0xff);
                        Send_buf[33] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G55.Value.ToString()) >> 8);
                        Send_buf[34] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G55.Value.ToString())) & 0xff);
                        Send_buf[35] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G63.Value.ToString()) >> 8);
                        Send_buf[36] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G63.Value.ToString())) & 0xff);

                        Send_buf[37] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G71.Value.ToString()) >> 8);
                        Send_buf[38] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G71.Value.ToString())) & 0xff);
                        Send_buf[39] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G79.Value.ToString()) >> 8);
                        Send_buf[40] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G79.Value.ToString())) & 0xff);
                        Send_buf[41] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G95.Value.ToString()) >> 8);
                        Send_buf[42] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G95.Value.ToString())) & 0xff);
                        Send_buf[43] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G111.Value.ToString()) >> 8);
                        Send_buf[44] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G111.Value.ToString())) & 0xff);
                        Send_buf[45] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G127.Value.ToString()) >> 8);
                        Send_buf[46] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G127.Value.ToString())) & 0xff);
                        Send_buf[47] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G159.Value.ToString()) >> 8);
                        Send_buf[48] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G159.Value.ToString())) & 0xff);
                        Send_buf[49] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G191.Value.ToString()) >> 8);
                        Send_buf[50] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G191.Value.ToString())) & 0xff);
                        Send_buf[51] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G223.Value.ToString()) >> 8);
                        Send_buf[52] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G223.Value.ToString())) & 0xff);

                        Send_buf[53] = Convert.ToByte(Convert.ToUInt16(VTDR6100_G255.Value.ToString()) >> 8);
                        Send_buf[54] = Convert.ToByte((Convert.ToUInt16(VTDR6100_G255.Value.ToString())) & 0xff);

                    }
                    break;

                case "UP_BLUE_GAMMA":     //      8
                    {
                        Send_buf[1] = 0x0A;
                        Send_buf[3] = 0x81;
                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(VTDR6100_Gamma_Group.Value.ToString()));

                        Send_buf[5] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B0.Value.ToString()) >> 8);
                        Send_buf[6] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B0.Value.ToString())) & 0xff);
                        Send_buf[7] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B1.Value.ToString()) >> 8);
                        Send_buf[8] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B1.Value.ToString())) & 0xff);
                        Send_buf[9] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B3.Value.ToString()) >> 8);
                        Send_buf[10] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B3.Value.ToString())) & 0xff);
                        Send_buf[11] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B5.Value.ToString()) >> 8);
                        Send_buf[12] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B5.Value.ToString())) & 0xff);
                        Send_buf[13] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B7.Value.ToString()) >> 8);
                        Send_buf[14] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B7.Value.ToString())) & 0xff);
                        Send_buf[15] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B11.Value.ToString()) >> 8);
                        Send_buf[16] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B11.Value.ToString())) & 0xff);
                        Send_buf[17] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B15.Value.ToString()) >> 8);
                        Send_buf[18] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B15.Value.ToString())) & 0xff);
                        Send_buf[19] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B19.Value.ToString()) >> 8);
                        Send_buf[20] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B19.Value.ToString())) & 0xff);

                        Send_buf[21] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B23.Value.ToString()) >> 8);
                        Send_buf[22] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B23.Value.ToString())) & 0xff);
                        Send_buf[23] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B27.Value.ToString()) >> 8);
                        Send_buf[24] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B27.Value.ToString())) & 0xff);
                        Send_buf[25] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B31.Value.ToString()) >> 8);
                        Send_buf[26] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B31.Value.ToString())) & 0xff);
                        Send_buf[27] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B35.Value.ToString()) >> 8);
                        Send_buf[28] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B35.Value.ToString())) & 0xff);
                        Send_buf[29] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B39.Value.ToString()) >> 8);
                        Send_buf[30] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B39.Value.ToString())) & 0xff);
                        Send_buf[31] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B47.Value.ToString()) >> 8);
                        Send_buf[32] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B47.Value.ToString())) & 0xff);
                        Send_buf[33] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B55.Value.ToString()) >> 8);
                        Send_buf[34] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B55.Value.ToString())) & 0xff);
                        Send_buf[35] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B63.Value.ToString()) >> 8);
                        Send_buf[36] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B63.Value.ToString())) & 0xff);

                        Send_buf[37] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B71.Value.ToString()) >> 8);
                        Send_buf[38] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B71.Value.ToString())) & 0xff);
                        Send_buf[39] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B79.Value.ToString()) >> 8);
                        Send_buf[40] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B79.Value.ToString())) & 0xff);
                        Send_buf[41] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B95.Value.ToString()) >> 8);
                        Send_buf[42] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B95.Value.ToString())) & 0xff);
                        Send_buf[43] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B111.Value.ToString()) >> 8);
                        Send_buf[44] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B111.Value.ToString())) & 0xff);
                        Send_buf[45] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B127.Value.ToString()) >> 8);
                        Send_buf[46] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B127.Value.ToString())) & 0xff);
                        Send_buf[47] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B159.Value.ToString()) >> 8);
                        Send_buf[48] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B159.Value.ToString())) & 0xff);
                        Send_buf[49] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B191.Value.ToString()) >> 8);
                        Send_buf[50] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B191.Value.ToString())) & 0xff);
                        Send_buf[51] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B223.Value.ToString()) >> 8);
                        Send_buf[52] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B223.Value.ToString())) & 0xff);

                        Send_buf[53] = Convert.ToByte(Convert.ToUInt16(VTDR6100_B255.Value.ToString()) >> 8);
                        Send_buf[54] = Convert.ToByte((Convert.ToUInt16(VTDR6100_B255.Value.ToString())) & 0xff);

                    }
                    break;

                default:
                    break;
            }
            CRCData.CalculateCrc16(Send_buf, out Send_buf[55], out Send_buf[56]);
            try
            {
                VTDR6100_0XFE_XX = 0x00;
                MainForm.comPort.Write(Send_buf, 0, 57);   //VTDR6100
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
                return;
            }
            T1.Enabled = false;
            T1.Interval = 2000;
            T1.Enabled = true;
        }

        private void VTDR6100_RegWR_Click(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;
            Int32 DataNum;
            string strLine = Convert.ToString(VTDR6100_txtRegData.Text);
            string[] arr = strLine.Split(','); //以逗号分割，添加到数组

            switch (btnTmp.Name)
            {
                case "VTDR6100_RegW":
                    {
                        Setting.TempRecord.cmdLen = arr.Length + 5;
                        Send_buf = new byte[arr.Length + 5];
                        Send_buf[0] = 0x4D;//VTDR6100

                        if (VTDR6100_rbt_LP.Checked == true)
                        { Send_buf[1] = 0x01; }
                        else if (VTDR6100_rbt_HS.Checked == true)
                        { Send_buf[1] = 0x81; }

                        Send_buf[2] = byte.Parse(arr.Length.ToString());
                        for (int i = 0; i < arr.Length; i++)
                        {
                            Send_buf[3 + i] = byte.Parse((Convert.ToInt32(arr[i], 16)).ToString());
                        }
                        CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + arr.Length - 2], out Send_buf[5 + arr.Length - 1]);
                        try
                        {
                            MainForm.comPort.Write(Send_buf, 0, 5 + arr.Length);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }
                    }
                    break;
                case "VTDR6100_51Reg_W":
                    {
                        Setting.TempRecord.cmdLen = arr.Length + 5;
                        Send_buf = new byte[arr.Length + 5];
                        Send_buf[0] = 0x4D;
                        Send_buf[1] = 0x03;
                        Send_buf[2] = byte.Parse(arr.Length.ToString());
                        for (int i = 0; i < arr.Length; i++)
                        {
                            Send_buf[3 + i] = byte.Parse((Convert.ToInt32(arr[i], 16)).ToString());
                        }
                        CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + arr.Length - 2], out Send_buf[5 + arr.Length - 1]);
                        try
                        {
                            MainForm.comPort.Write(Send_buf, 0, 5 + arr.Length);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }
                    }
                    break;
                case "VTDR6100_RegR":
                    {
                        Setting.TempRecord.VTDR6100CmdType = 0x02;
                        try
                        {
                            DataNum = Convert.ToInt32(VTDR6100_txtDataNum.Text) + 1;
                            Setting.TempRecord.cmdLen = DataNum + 5;
                            Send_buf = new byte[DataNum + 5];
                            Send_buf[0] = 0x4D; //VTDR6100
                            Send_buf[1] = 0x02;
                            Send_buf[2] = byte.Parse(Convert.ToString(DataNum));
                            Send_buf[3] = byte.Parse((Convert.ToInt32(arr[0], 16)).ToString());  //cmd
                            CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + DataNum - 2], out Send_buf[5 + DataNum - 1]);
                        }
                        catch
                        {
                            MessageBox.Show("读取长度有误，请检查", "错误");
                            break;
                        }
                        try
                        {
                            MainForm.comPort.Write(Send_buf, 0, 5 + DataNum);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }
                    }
                    break;
                case "Demura_on":
                    {
                        strLine = Convert.ToString("59,09");
                        arr = strLine.Split(','); //以逗号分割，添加到数组

                        Setting.TempRecord.cmdLen = 2 + 5;
                        Send_buf = new byte[2 + 5];
                        Send_buf[0] = 0x4D;//VTDR6100
                        Send_buf[1] = 0x01;

                        Send_buf[2] = 2;
                        Send_buf[3 + 0] = 0x59;
                        Send_buf[3 + 1] = 0x09;

                        CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + arr.Length - 2], out Send_buf[5 + arr.Length - 1]);
                        try
                        {
                            MainForm.comPort.Write(Send_buf, 0, 5 + arr.Length);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }
                        textBox1.Text = textBox1.Text + "Demura on \r\n";
                    }
                    break;
                case "Demura_off":
                    {
                        strLine = Convert.ToString("59,00");
                        arr = strLine.Split(','); //以逗号分割，添加到数组

                        Setting.TempRecord.cmdLen = arr.Length + 5;
                        Send_buf = new byte[arr.Length + 5];
                        Send_buf[0] = 0x4D;//VTDR6100
                        Send_buf[1] = 0x01;

                        Send_buf[2] = 2;
                        Send_buf[3 + 0] = 0x59;
                        Send_buf[3 + 1] = 0x00;

                        CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + arr.Length - 2], out Send_buf[5 + arr.Length - 1]);
                        try
                        {
                            MainForm.comPort.Write(Send_buf, 0, 5 + arr.Length);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }
                        textBox1.Text = textBox1.Text + "Demura off \r\n";
                    }
                    break;
                default: break;
            }
            T1.Enabled = false;
            T1.Interval = 2000;
            T1.Enabled = true;
        }

        private void VTDR6100_trackBar_Scroll(object sender, EventArgs e)
        {
            VTDR6100_label.Text = VTDR6100_51Reg_trackBar.Value.ToString() + "阶";
            VTDR6100_txtRegData.Text = "51,00," + VTDR6100_51Reg_trackBar.Value.ToString("x2");
            VTDR6100_RegWR_Click(VTDR6100_51Reg_W, e);
        }

        private void VTDR6100_Others_Click(object sender, EventArgs e)
        {
            Send_buf = new byte[7];
            Button btnTmp = (Button)sender;
            Setting.TempRecord.cmdLen = 7;

            Send_buf[0] = 0x4D;
            Send_buf[2] = 0x02;

            switch (btnTmp.Name)
            {
                case "VTDR6100_W2810": //otp Gamma       A  
                    {
                        VTDR6100_0XFE_XX = 0x00;
                        Send_buf[1] = 0x1F;
                    }
                    break;
                case "VTDR6100_OTP_Gamma": //otp Gamma       A  
                    {
                        VTDR6100_0XFE_XX = 0x00;
                        Send_buf[1] = 0x0D;
                    }
                    break;
                case "VTDR6100_OTP_ALL"://otp GOA        D
                    {
                        VTDR6100_0XFE_XX = 0x00;
                        Send_buf[1] = 0x0E;
                    }
                    break;
                case "VTDR6100_OTP_P4"://otp POWER        E
                    {
                        VTDR6100_0XFE_XX = 0x00;
                        Send_buf[1] = 0x1A;
                    }
                    break;
                case "VTDR6100_OTP_P0"://otp OTHERS                    F
                    {
                        VTDR6100_0XFE_XX = 0x00;
                        Send_buf[1] = 0x0F;
                    }
                    break;
                case "VTDR6100_OTP_P1":       //          B
                    {
                        VTDR6100_0XFE_XX = 0x00;
                        Send_buf[1] = 0x1B;
                    }
                    break;
                case "VTDR6100_OTP_P2":         //w写寄存器   C
                    {
                        VTDR6100_0XFE_XX = 0x00;
                        Send_buf[1] = 0x1C;
                    }
                    break;
                case "VTDR6100_OTP_P5":         //w写寄存器   C
                    {
                        VTDR6100_0XFE_XX = 0x00;
                        Send_buf[1] = 0x1D;
                    }
                    break;
                case "VTDR6100_OTP_P7":         //w写寄存器   C
                    {
                        VTDR6100_0XFE_XX = 0x00;
                        Send_buf[1] = 0x1E;
                    }
                    break;
                case "Read_Flash_ID":         //读Flash ID
                    {
                        VTDR6100_0XFE_XX = 0x00;
                        Send_buf[1] = 0x20;
                    }
                    break;
                case "Erase_Flash":         //擦除Flash
                    {
                        VTDR6100_0XFE_XX = 0x00;
                        Send_buf[1] = 0x21;
                        textBox1.Text = textBox1.Text + "Please Wait for 50 seconds\r\n";
                    }
                    break;
                case "Flash_Status":         //确认Flash Status
                    {
                        VTDR6100_0XFE_XX = 0x00;
                        Send_buf[1] = 0x22;
                        //textBox1.Text = textBox1.Text + "Please Wait for 30 seconds\r\n";
                    }
                    break;
                case "Check_Flash":         //确认Flash Status
                    {
                        VTDR6100_0XFE_XX = 0x00;
                        Send_buf[1] = 0x23;
                        Setting.TempRecord.cmdLen = 13;////CRC 特殊处理
                        //textBox1.Text = textBox1.Text + "Please Wait for 30 seconds\r\n";
                    }
                    break;
                case "Five_Step":         //确认Flash Status
                    {
                        VTDR6100_0XFE_XX = 0x00;
                        Send_buf[1] = 0x24;
                        //Setting.TempRecord.cmdLen = 14;////CRC 特殊处理
                        //textBox1.Text = textBox1.Text + "Please Wait for 30 seconds\r\n";
                    }
                    break;
                case "OTP_Flash":         //确认Flash Status
                    {
                        VTDR6100_0XFE_XX = 0x00;
                        Send_buf[1] = 0x25;
                        textBox1.Text = textBox1.Text + "OTP Please Wait for 40 seconds\r\n";
                    }
                    break;
                case "CRC_check":
                    {
                        VTDR6100_0XFE_XX = 0x00;
                        Send_buf[1] = 0x26;
                        Setting.TempRecord.cmdLen = 14;////CRC 特殊处理
                        textBox1.Text = textBox1.Text + "CRC_check\r\n";
                    }
                    break;
                case "button4":
                    {
                        VTDR6100_0XFE_XX = 0x00;
                        Send_buf[1] = 0x27;///reset 
                        textBox1.Text = textBox1.Text + "reset system \r\n";
                    }
                    break;
                default:
                    break;
            }

            CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
            try
            {
                MainForm.comPort.Write(Send_buf, 0, 7);
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
            T1.Enabled = false;
            T1.Interval = 2000;
            T1.Enabled = true;
        }

        private int[] Parttern_VTDR6100 = new int[14] { 255, 223, 191, 127, 111, 79, 63, 55, 47, 39, 35, 31, 11, 3 };
        private void btnCalculate_VTDR6100_Click(object sender, EventArgs e)
        {
            txtVT_255.Text = (Math.Pow((Parttern_VTDR6100[0] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_223.Text = (Math.Pow((Parttern_VTDR6100[1] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_191.Text = (Math.Pow((Parttern_VTDR6100[2] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_127.Text = (Math.Pow((Parttern_VTDR6100[3] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_111.Text = (Math.Pow((Parttern_VTDR6100[4] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_79.Text = (Math.Pow((Parttern_VTDR6100[5] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_63.Text = (Math.Pow((Parttern_VTDR6100[6] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_55.Text = (Math.Pow((Parttern_VTDR6100[7] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_47.Text = (Math.Pow((Parttern_VTDR6100[8] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_39.Text = (Math.Pow((Parttern_VTDR6100[9] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_35.Text = (Math.Pow((Parttern_VTDR6100[10] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_31.Text = (Math.Pow((Parttern_VTDR6100[11] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_11.Text = (Math.Pow((Parttern_VTDR6100[12] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
            txtVT_3.Text = (Math.Pow((Parttern_VTDR6100[13] / 255.0), Convert.ToDouble(txtVT_gamma.Text)) * Convert.ToDouble(txtVT_lum.Text)).ToString("F4");
        }

        private void T17_Tick(object sender, EventArgs e)
        {
            double Lr_t, Lg_t, Lb_t, lumr, lumg, lumb;

            //if (Msr_CA310() == false)
            {
                //    return;
            }
            Msr_CA310();

            if ((auto_lum < (D_lum[index] + lum_off)) && (auto_lum > (D_lum[index] - lum_off)))//G
                flag1 = 0;
            if ((auto_y < (D_y + y_off)) && (auto_y > (D_y - y_off)) && flag1 == 0)//B
                flag2 = 0;
            if ((auto_x < (D_x + x_off)) && (auto_x > (D_x - x_off)) && flag1 == 0 && flag2 == 0)//R
                flag3 = 0;

            if (flag1 == 0 && flag2 == 0 && flag3 == 0)
            {
                T17.Enabled = false;
                index++;
                adjust_Rnum = 0;
                adjust_Gnum = 0;
                adjust_Bnum = 0;
                adjust_l = 0;
                adjust_x = 0;
                adjust_y = 0;
                if (index == 14)
                {
                    textBox1.Text = textBox1.Text + "VTDR6100 gamma调试完毕!\r\n";
                }
                if (index < 14)
                {

                    switch (index)
                    {
                        case 1:
                            lum_off = Convert.ToDouble(textVT_223_off.Text);
                            break;

                        case 2:
                            lum_off = Convert.ToDouble(textVT_191_off.Text);
                            break;

                        case 3:
                            lum_off = Convert.ToDouble(textVT_127_off.Text) * Convert.ToDouble(txtVT_127.Text) / 100;
                            break;

                        case 4:
                            lum_off = Convert.ToDouble(textVT_111_off.Text) * Convert.ToDouble(txtVT_111.Text) / 100;
                            break;

                        case 5:
                            lum_off = Convert.ToDouble(textVT_79_off.Text) * Convert.ToDouble(txtVT_79.Text) / 100;
                            break;

                        case 6:
                            lum_off = Convert.ToDouble(textVT_63_off.Text) * Convert.ToDouble(txtVT_63.Text) / 100;
                            break;

                        case 7:
                            lum_off = Convert.ToDouble(textVT_55_off.Text) * Convert.ToDouble(txtVT_55.Text) / 100;
                            break;

                        case 8:
                            lum_off = Convert.ToDouble(textVT_47_off.Text) * Convert.ToDouble(txtVT_47.Text) / 100;
                            break;

                        case 9:
                            lum_off = Convert.ToDouble(textVT_39_off.Text) * Convert.ToDouble(txtVT_39.Text) / 100;
                            break;

                        case 10:
                            lum_off = Convert.ToDouble(textVT_35_off.Text) * Convert.ToDouble(txtVT_35.Text) / 100;
                            break;

                        case 11:
                            lum_off = Convert.ToDouble(textVT_31_off.Text) * Convert.ToDouble(txtVT_31.Text) / 100;
                            break;
                        case 12:
                            {
                                lum_off = Convert.ToDouble(textVT_11_off.Text) * Convert.ToDouble(txtVT_11.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                            }
                            break;
                        case 13:
                            {
                                lum_off = Convert.ToDouble(textVT_3_off.Text) * Convert.ToDouble(txtVT_3.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                            }
                            break;

                    }
                    numPatternR.Value = Parttern_VTDR6100[index];
                    numPatternG.Value = Parttern_VTDR6100[index];
                    numPatternB.Value = Parttern_VTDR6100[index];
                    OLED_Show_Click(btnPatternW, e);//写入Pattern参数
                    Thread.Sleep(10); //1秒=1000毫秒，
                    T17.Enabled = true;
                    flag1 = 1;
                    flag2 = 1;
                    flag3 = 1;
                }
            }
            else
            {
                Lr_t = R_y * ((auto_y - G_y) * (B_x - auto_x) + (auto_x - G_x) * (auto_y - B_y)) / B_y / ((auto_y - G_y) * (auto_x - R_x) + (auto_x - G_x) * (R_y - auto_y));
                Lb_t = 1.0;
                Lg_t = G_y * ((auto_y - R_y) * (B_x - auto_x) + (auto_x - R_x) * (auto_y - B_y)) / B_y / ((auto_y - R_y) * (auto_x - G_x) + (auto_x - R_x) * (G_y - auto_y));
                lumr = auto_lum * Lr_t / (Lr_t + Lg_t + Lb_t);
                lumg = auto_lum * Lg_t / (Lr_t + Lg_t + Lb_t);
                lumb = auto_lum * Lb_t / (Lr_t + Lg_t + Lb_t);

                //try
                {
                    switch (index)
                    {
                        case 0:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R255.Value = VTDR6100_R255.Value - step_h;
                                        else VTDR6100_R255.Value = VTDR6100_R255.Value + step_h;
                                        adjust_Rnum = 0;
                                        if (VTDR6100_R255.Value >= 0x3FF)
                                            VTDR6100_R255.Value = VTDR6100_R223.Value + step_h;
                                        /*if (VTDR6100_R255.Value <= VTDR6100_R223.Value)
                                            VTDR6100_R255.Value = VTDR6100_R223.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R255.Value = VTDR6100_R255.Value - step_l;
                                        else VTDR6100_R255.Value = VTDR6100_R255.Value + step_l;
                                        /*if (VTDR6100_R255.Value <= VTDR6100_R223.Value)
                                            VTDR6100_R255.Value = VTDR6100_R223.Value + step_h;*/
                                        if (VTDR6100_R255.Value >= 0x3FF)
                                            VTDR6100_R255.Value = VTDR6100_R223.Value + step_h;
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G255.Value = VTDR6100_G255.Value - step_h;
                                        else VTDR6100_G255.Value = VTDR6100_G255.Value + step_h;
                                        adjust_Gnum = 0;
                                        if (VTDR6100_G255.Value >= 0x3FF)
                                            VTDR6100_G255.Value = VTDR6100_G223.Value + step_h;
                                        /*if (VTDR6100_G255.Value <= VTDR6100_G223.Value)
                                            VTDR6100_G255.Value = VTDR6100_G223.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G255.Value = VTDR6100_G255.Value - step_l;
                                        else VTDR6100_G255.Value = VTDR6100_G255.Value + step_l;
                                        if (VTDR6100_G255.Value >= 0x3FF)
                                            VTDR6100_G255.Value = VTDR6100_G223.Value + step_h;
                                        /*if (VTDR6100_G255.Value <= VTDR6100_G223.Value)
                                            VTDR6100_G255.Value = VTDR6100_G223.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B255.Value = VTDR6100_B255.Value - step_h;
                                        else VTDR6100_B255.Value = VTDR6100_B255.Value + step_h;
                                        adjust_Bnum = 0;
                                        if (VTDR6100_B255.Value >= 0x3FF)
                                            VTDR6100_B255.Value = VTDR6100_B223.Value + step_h;
                                        /*if (VTDR6100_B255.Value <= VTDR6100_B223.Value)
                                            VTDR6100_B255.Value = VTDR6100_B223.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B255.Value = VTDR6100_B255.Value - step_l;
                                        else VTDR6100_B255.Value = VTDR6100_B255.Value + step_l;
                                        if (VTDR6100_B255.Value >= 0x3FF)
                                            VTDR6100_B255.Value = VTDR6100_B223.Value + step_h;
                                        /*if (VTDR6100_B255.Value <= VTDR6100_B223.Value)
                                            VTDR6100_B255.Value = VTDR6100_B223.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }

                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Red, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Green, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 1:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R223.Value = VTDR6100_R223.Value - step_h;
                                        else VTDR6100_R223.Value = VTDR6100_R223.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR6100_R223.Value <= VTDR6100_R191.Value)
                                            VTDR6100_R223.Value = VTDR6100_R191.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R223.Value = VTDR6100_R223.Value - step_l;
                                        else VTDR6100_R223.Value = VTDR6100_R223.Value + step_l;
                                        /*if(VTDR6100_R223.Value <= VTDR6100_R191.Value)
                                            VTDR6100_R223.Value = VTDR6100_R191.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G223.Value = VTDR6100_G223.Value - step_h;
                                        else VTDR6100_G223.Value = VTDR6100_G223.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if(VTDR6100_G223.Value <= VTDR6100_G191.Value)
                                            VTDR6100_G223.Value = VTDR6100_G191.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G223.Value = VTDR6100_G223.Value - step_l;
                                        else VTDR6100_G223.Value = VTDR6100_G223.Value + step_l;
                                        /*if(VTDR6100_G223.Value <= VTDR6100_G191.Value)
                                            VTDR6100_G223.Value = VTDR6100_G191.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B223.Value = VTDR6100_B223.Value - step_h;
                                        else VTDR6100_B223.Value = VTDR6100_B223.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if(VTDR6100_B223.Value <= VTDR6100_B191.Value)
                                            VTDR6100_B223.Value = VTDR6100_B191.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B223.Value = VTDR6100_B223.Value - step_l;
                                        else VTDR6100_B223.Value = VTDR6100_B223.Value + step_l;
                                        /*if(VTDR6100_B223.Value <= VTDR6100_B191.Value)
                                            VTDR6100_B223.Value = VTDR6100_B191.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Red, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Green, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;
                        case 2:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R191.Value = VTDR6100_R191.Value - step_h;
                                        else VTDR6100_R191.Value = VTDR6100_R191.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if(VTDR6100_R191.Value <= VTDR6100_R159.Value)
                                            VTDR6100_R191.Value = VTDR6100_R159.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R191.Value = VTDR6100_R191.Value - step_l;
                                        else VTDR6100_R191.Value = VTDR6100_R191.Value + step_l;
                                        /*if(VTDR6100_R191.Value <= VTDR6100_R159.Value)
                                            VTDR6100_R191.Value = VTDR6100_R159.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G191.Value = VTDR6100_G191.Value - step_h;
                                        else VTDR6100_G191.Value = VTDR6100_G191.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if(VTDR6100_G191.Value <= VTDR6100_G159.Value)
                                            VTDR6100_G191.Value = VTDR6100_G159.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G191.Value = VTDR6100_G191.Value - step_l;
                                        else VTDR6100_G191.Value = VTDR6100_G191.Value + step_l;
                                        /*if(VTDR6100_G191.Value <= VTDR6100_G159.Value)
                                            VTDR6100_G191.Value = VTDR6100_G159.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B191.Value = VTDR6100_B191.Value - step_h;
                                        else VTDR6100_B191.Value = VTDR6100_B191.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if(VTDR6100_B191.Value <= VTDR6100_B159.Value)
                                            VTDR6100_B191.Value = VTDR6100_B159.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B191.Value = VTDR6100_B191.Value - step_l;
                                        else VTDR6100_B191.Value = VTDR6100_B191.Value + step_l;
                                        /*if(VTDR6100_B191.Value <= VTDR6100_B159.Value)
                                            VTDR6100_B191.Value = VTDR6100_B159.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Red, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Green, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 3:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R127.Value = VTDR6100_R127.Value - step_h;
                                        else VTDR6100_R127.Value = VTDR6100_R127.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if(VTDR6100_R127.Value <= VTDR6100_R111.Value)
                                            VTDR6100_R127.Value = VTDR6100_R111.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R127.Value = VTDR6100_R127.Value - step_l;
                                        else VTDR6100_R127.Value = VTDR6100_R127.Value + step_l;
                                        /*if (VTDR6100_R127.Value <= VTDR6100_R111.Value)
                                            VTDR6100_R127.Value = VTDR6100_R111.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G127.Value = VTDR6100_G127.Value - step_h;
                                        else VTDR6100_G127.Value = VTDR6100_G127.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR6100_G127.Value <= VTDR6100_G111.Value)
                                            VTDR6100_G127.Value = VTDR6100_G111.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G127.Value = VTDR6100_G127.Value - step_l;
                                        else VTDR6100_G127.Value = VTDR6100_G127.Value + step_l;
                                        /*if (VTDR6100_G127.Value <= VTDR6100_G111.Value)
                                            VTDR6100_G127.Value = VTDR6100_G111.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B127.Value = VTDR6100_B127.Value - step_h;
                                        else VTDR6100_B127.Value = VTDR6100_B127.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR6100_B127.Value <= VTDR6100_B111.Value)
                                            VTDR6100_B127.Value = VTDR6100_B111.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B127.Value = VTDR6100_B127.Value - step_l;
                                        else VTDR6100_B127.Value = VTDR6100_B127.Value + step_l;
                                        /*if (VTDR6100_B127.Value <= VTDR6100_B111.Value)
                                            VTDR6100_B127.Value = VTDR6100_B111.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Red, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Green, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 4:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R111.Value = VTDR6100_R111.Value - step_h;
                                        else VTDR6100_R111.Value = VTDR6100_R111.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if(VTDR6100_R127.Value <= VTDR6100_R111.Value)
                                            VTDR6100_R127.Value = VTDR6100_R111.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R111.Value = VTDR6100_R111.Value - step_l;
                                        else VTDR6100_R111.Value = VTDR6100_R111.Value + step_l;
                                        /*if (VTDR6100_R127.Value <= VTDR6100_R111.Value)
                                            VTDR6100_R127.Value = VTDR6100_R111.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G111.Value = VTDR6100_G111.Value - step_h;
                                        else VTDR6100_G111.Value = VTDR6100_G111.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR6100_G127.Value <= VTDR6100_G111.Value)
                                            VTDR6100_G127.Value = VTDR6100_G111.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G111.Value = VTDR6100_G111.Value - step_l;
                                        else VTDR6100_G111.Value = VTDR6100_G111.Value + step_l;
                                        /*if (VTDR6100_G127.Value <= VTDR6100_G111.Value)
                                            VTDR6100_G127.Value = VTDR6100_G111.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B111.Value = VTDR6100_B111.Value - step_h;
                                        else VTDR6100_B111.Value = VTDR6100_B111.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR6100_B127.Value <= VTDR6100_B111.Value)
                                            VTDR6100_B127.Value = VTDR6100_B111.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B111.Value = VTDR6100_B111.Value - step_l;
                                        else VTDR6100_B111.Value = VTDR6100_B111.Value + step_l;
                                        /*if (VTDR6100_B127.Value <= VTDR6100_B111.Value)
                                            VTDR6100_B127.Value = VTDR6100_B111.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Red, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Green, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 5:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R79.Value = VTDR6100_R79.Value - step_h;
                                        else VTDR6100_R79.Value = VTDR6100_R79.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if(VTDR6100_R127.Value <= VTDR6100_R111.Value)
                                            VTDR6100_R127.Value = VTDR6100_R111.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R79.Value = VTDR6100_R79.Value - step_l;
                                        else VTDR6100_R79.Value = VTDR6100_R79.Value + step_l;
                                        /*if (VTDR6100_R127.Value <= VTDR6100_R111.Value)
                                            VTDR6100_R127.Value = VTDR6100_R111.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G79.Value = VTDR6100_G79.Value - step_h;
                                        else VTDR6100_G79.Value = VTDR6100_G79.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR6100_G127.Value <= VTDR6100_G111.Value)
                                            VTDR6100_G127.Value = VTDR6100_G111.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G79.Value = VTDR6100_G79.Value - step_l;
                                        else VTDR6100_G79.Value = VTDR6100_G79.Value + step_l;
                                        /*if (VTDR6100_G127.Value <= VTDR6100_G111.Value)
                                            VTDR6100_G127.Value = VTDR6100_G111.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B79.Value = VTDR6100_B79.Value - step_h;
                                        else VTDR6100_B79.Value = VTDR6100_B79.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR6100_B127.Value <= VTDR6100_B111.Value)
                                            VTDR6100_B127.Value = VTDR6100_B111.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B79.Value = VTDR6100_B79.Value - step_l;
                                        else VTDR6100_B79.Value = VTDR6100_B79.Value + step_l;
                                        /*if (VTDR6100_B127.Value <= VTDR6100_B111.Value)
                                            VTDR6100_B127.Value = VTDR6100_B111.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Red, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Green, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 6:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R63.Value = VTDR6100_R63.Value - step_h;
                                        else VTDR6100_R63.Value = VTDR6100_R63.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR6100_R63.Value <= VTDR6100_R55.Value)
                                            VTDR6100_R63.Value = VTDR6100_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R63.Value = VTDR6100_R63.Value - step_l;
                                        else VTDR6100_R63.Value = VTDR6100_R63.Value + step_l;
                                        /*if (VTDR6100_R63.Value <= VTDR6100_R55.Value)
                                            VTDR6100_R63.Value = VTDR6100_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G63.Value = VTDR6100_G63.Value - step_h;
                                        else VTDR6100_G63.Value = VTDR6100_G63.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR6100_G63.Value <= VTDR6100_G55.Value)
                                            VTDR6100_G63.Value = VTDR6100_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G63.Value = VTDR6100_G63.Value - step_l;
                                        else VTDR6100_G63.Value = VTDR6100_G63.Value + step_l;
                                        /*if (VTDR6100_G63.Value <= VTDR6100_G55.Value)
                                            VTDR6100_G63.Value = VTDR6100_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B63.Value = VTDR6100_B63.Value - step_h;
                                        else VTDR6100_B63.Value = VTDR6100_B63.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR6100_B63.Value <= VTDR6100_B55.Value)
                                            VTDR6100_B63.Value = VTDR6100_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B63.Value = VTDR6100_B63.Value - step_l;
                                        else VTDR6100_B63.Value = VTDR6100_B63.Value + step_l;
                                        /*if (VTDR6100_B63.Value <= VTDR6100_B55.Value)
                                            VTDR6100_B63.Value = VTDR6100_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Red, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Green, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 7:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R55.Value = VTDR6100_R55.Value - step_h;
                                        else VTDR6100_R55.Value = VTDR6100_R55.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR6100_R63.Value <= VTDR6100_R55.Value)
                                            VTDR6100_R63.Value = VTDR6100_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R55.Value = VTDR6100_R55.Value - step_l;
                                        else VTDR6100_R55.Value = VTDR6100_R55.Value + step_l;
                                        /*if (VTDR6100_R63.Value <= VTDR6100_R55.Value)
                                            VTDR6100_R63.Value = VTDR6100_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G55.Value = VTDR6100_G55.Value - step_h;
                                        else VTDR6100_G55.Value = VTDR6100_G55.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR6100_G63.Value <= VTDR6100_G55.Value)
                                            VTDR6100_G63.Value = VTDR6100_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G55.Value = VTDR6100_G55.Value - step_l;
                                        else VTDR6100_G55.Value = VTDR6100_G55.Value + step_l;
                                        /*if (VTDR6100_G63.Value <= VTDR6100_G55.Value)
                                            VTDR6100_G63.Value = VTDR6100_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B55.Value = VTDR6100_B55.Value - step_h;
                                        else VTDR6100_B55.Value = VTDR6100_B55.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR6100_B63.Value <= VTDR6100_B55.Value)
                                            VTDR6100_B63.Value = VTDR6100_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B55.Value = VTDR6100_B55.Value - step_l;
                                        else VTDR6100_B55.Value = VTDR6100_B55.Value + step_l;
                                        /*if (VTDR6100_B63.Value <= VTDR6100_B55.Value)
                                            VTDR6100_B63.Value = VTDR6100_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Red, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Green, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 8:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R47.Value = VTDR6100_R47.Value - step_h;
                                        else VTDR6100_R47.Value = VTDR6100_R47.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR6100_R63.Value <= VTDR6100_R55.Value)
                                            VTDR6100_R63.Value = VTDR6100_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R47.Value = VTDR6100_R47.Value - step_l;
                                        else VTDR6100_R47.Value = VTDR6100_R47.Value + step_l;
                                        /*if (VTDR6100_R63.Value <= VTDR6100_R55.Value)
                                            VTDR6100_R63.Value = VTDR6100_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G47.Value = VTDR6100_G47.Value - step_h;
                                        else VTDR6100_G47.Value = VTDR6100_G47.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR6100_G63.Value <= VTDR6100_G55.Value)
                                            VTDR6100_G63.Value = VTDR6100_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G47.Value = VTDR6100_G47.Value - step_l;
                                        else VTDR6100_G47.Value = VTDR6100_G47.Value + step_l;
                                        /*if (VTDR6100_G63.Value <= VTDR6100_G55.Value)
                                            VTDR6100_G63.Value = VTDR6100_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B47.Value = VTDR6100_B47.Value - step_h;
                                        else VTDR6100_B47.Value = VTDR6100_B47.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR6100_B63.Value <= VTDR6100_B55.Value)
                                            VTDR6100_B63.Value = VTDR6100_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B47.Value = VTDR6100_B47.Value - step_l;
                                        else VTDR6100_B47.Value = VTDR6100_B47.Value + step_l;
                                        /*if (VTDR6100_B63.Value <= VTDR6100_B55.Value)
                                            VTDR6100_B63.Value = VTDR6100_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Red, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Green, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 9:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R39.Value = VTDR6100_R39.Value - step_h;
                                        else VTDR6100_R39.Value = VTDR6100_R39.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR6100_R63.Value <= VTDR6100_R55.Value)
                                            VTDR6100_R63.Value = VTDR6100_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R39.Value = VTDR6100_R39.Value - step_l;
                                        else VTDR6100_R39.Value = VTDR6100_R39.Value + step_l;
                                        /*if (VTDR6100_R63.Value <= VTDR6100_R55.Value)
                                            VTDR6100_R63.Value = VTDR6100_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G39.Value = VTDR6100_G39.Value - step_h;
                                        else VTDR6100_G39.Value = VTDR6100_G39.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR6100_G63.Value <= VTDR6100_G55.Value)
                                            VTDR6100_G63.Value = VTDR6100_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G39.Value = VTDR6100_G39.Value - step_l;
                                        else VTDR6100_G39.Value = VTDR6100_G39.Value + step_l;
                                        /*if (VTDR6100_G63.Value <= VTDR6100_G55.Value)
                                            VTDR6100_G63.Value = VTDR6100_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B39.Value = VTDR6100_B39.Value - step_h;
                                        else VTDR6100_B39.Value = VTDR6100_B39.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR6100_B63.Value <= VTDR6100_B55.Value)
                                            VTDR6100_B63.Value = VTDR6100_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B39.Value = VTDR6100_B39.Value - step_l;
                                        else VTDR6100_B39.Value = VTDR6100_B39.Value + step_l;
                                        /*if (VTDR6100_B63.Value <= VTDR6100_B55.Value)
                                            VTDR6100_B63.Value = VTDR6100_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Red, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Green, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 10:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R35.Value = VTDR6100_R35.Value - step_h;
                                        else VTDR6100_R35.Value = VTDR6100_R35.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR6100_R63.Value <= VTDR6100_R55.Value)
                                            VTDR6100_R63.Value = VTDR6100_R55.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R35.Value = VTDR6100_R35.Value - step_l;
                                        else VTDR6100_R35.Value = VTDR6100_R35.Value + step_l;
                                        /*if (VTDR6100_R63.Value <= VTDR6100_R55.Value)
                                            VTDR6100_R63.Value = VTDR6100_R55.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G35.Value = VTDR6100_G35.Value - step_h;
                                        else VTDR6100_G35.Value = VTDR6100_G35.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR6100_G63.Value <= VTDR6100_G55.Value)
                                            VTDR6100_G63.Value = VTDR6100_G55.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G35.Value = VTDR6100_G35.Value - step_l;
                                        else VTDR6100_G35.Value = VTDR6100_G35.Value + step_l;
                                        /*if (VTDR6100_G63.Value <= VTDR6100_G55.Value)
                                            VTDR6100_G63.Value = VTDR6100_G55.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B35.Value = VTDR6100_B35.Value - step_h;
                                        else VTDR6100_B35.Value = VTDR6100_B35.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR6100_B63.Value <= VTDR6100_B55.Value)
                                            VTDR6100_B63.Value = VTDR6100_B55.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B35.Value = VTDR6100_B35.Value - step_l;
                                        else VTDR6100_B35.Value = VTDR6100_B35.Value + step_l;
                                        /*if (VTDR6100_B63.Value <= VTDR6100_B55.Value)
                                            VTDR6100_B63.Value = VTDR6100_B55.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Red, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Green, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 11:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R31.Value = VTDR6100_R31.Value - step_h;
                                        else VTDR6100_R31.Value = VTDR6100_R31.Value + step_h;
                                        adjust_Rnum = 0;
                                        /*if (VTDR6100_R31.Value <= VTDR6100_R27.Value)
                                            VTDR6100_R31.Value = VTDR6100_R27.Value + step_h;*/
                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R31.Value = VTDR6100_R31.Value - step_l;
                                        else VTDR6100_R31.Value = VTDR6100_R31.Value + step_l;
                                        /*if (VTDR6100_R31.Value <= VTDR6100_R27.Value)
                                            VTDR6100_R31.Value = VTDR6100_R27.Value + step_h;*/
                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G31.Value = VTDR6100_G31.Value - step_h;
                                        else VTDR6100_G31.Value = VTDR6100_G31.Value + step_h;
                                        adjust_Gnum = 0;
                                        /*if (VTDR6100_G31.Value <= VTDR6100_G27.Value)
                                            VTDR6100_G31.Value = VTDR6100_G27.Value + step_h;*/
                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G31.Value = VTDR6100_G31.Value - step_l;
                                        else VTDR6100_G31.Value = VTDR6100_G31.Value + step_l;
                                        /*if (VTDR6100_G31.Value <= VTDR6100_G27.Value)
                                            VTDR6100_G31.Value = VTDR6100_G27.Value + step_h;*/
                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B31.Value = VTDR6100_B31.Value - step_h;
                                        else VTDR6100_B31.Value = VTDR6100_B31.Value + step_h;
                                        adjust_Bnum = 0;
                                        /*if (VTDR6100_B31.Value <= VTDR6100_B27.Value)
                                            VTDR6100_B31.Value = VTDR6100_B27.Value + step_h;*/
                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B31.Value = VTDR6100_B31.Value - step_l;
                                        else VTDR6100_B31.Value = VTDR6100_B31.Value + step_l;
                                        /*if (VTDR6100_B31.Value <= VTDR6100_B27.Value)
                                            VTDR6100_B31.Value = VTDR6100_B27.Value + step_h;*/
                                    }
                                    adjust_Bnum++;
                                }
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Red, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Green, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 12:
                            {
                                if (flag3 == 1)
                                {
                                    if (adjust_Rnum > 10)
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R11.Value = VTDR6100_R11.Value - step_h;
                                        else VTDR6100_R11.Value = VTDR6100_R11.Value + step_h;
                                        adjust_Rnum = 0;

                                        adjust_x++;
                                        if (adjust_x > 50)
                                        {
                                            x_off += 0.0005;
                                            adjust_x = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumr > D_lums[index, 0])
                                            VTDR6100_R11.Value = VTDR6100_R11.Value - step_l;
                                        else VTDR6100_R11.Value = VTDR6100_R11.Value + step_l;

                                    }
                                    adjust_Rnum++;
                                }
                                if (flag1 == 1)
                                {
                                    if (adjust_Gnum > 10)
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G11.Value = VTDR6100_G11.Value - step_h;
                                        else VTDR6100_G11.Value = VTDR6100_G11.Value + step_h;
                                        adjust_Gnum = 0;

                                        adjust_l++;
                                        if (adjust_l > 50)
                                        {
                                            lum_off *= 1.5;
                                            adjust_l = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumg > D_lums[index, 1])
                                            VTDR6100_G11.Value = VTDR6100_G11.Value - step_l;
                                        else VTDR6100_G11.Value = VTDR6100_G11.Value + step_l;

                                    }
                                    adjust_Gnum++;
                                }
                                if (flag2 == 1)
                                {
                                    if (adjust_Bnum > 10)
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B11.Value = VTDR6100_B11.Value - step_h;
                                        else VTDR6100_B11.Value = VTDR6100_B11.Value + step_h;
                                        adjust_Bnum = 0;

                                        adjust_y++;
                                        if (adjust_y > 50)
                                        {
                                            y_off += 0.0005;
                                            adjust_y = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (lumb > D_lums[index, 2])
                                            VTDR6100_B11.Value = VTDR6100_B11.Value - step_l;
                                        else VTDR6100_B11.Value = VTDR6100_B11.Value + step_l;

                                    }
                                    adjust_Bnum++;
                                }
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Red, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Green, e);
                                VTDR6100_GAMMA_Click(VTDR6100_GammaW_Blue, e);
                                //Thread.Sleep(100);
                            }
                            break;

                        case 13:
                            {
                                for (int k = 0; k < 13; k++)
                                {
                                    numPatternR.Value = Parttern_VTDR6100[k];
                                    numPatternG.Value = Parttern_VTDR6100[k];
                                    numPatternB.Value = Parttern_VTDR6100[k];
                                    OLED_Show_Click(btnPatternW, e);//写入Pattern参数
                                    Thread.Sleep(1000); //1秒=1000毫秒，
                                    Msr_CA310();
                                    CAS200_Measure_Information(auto_lum, auto_x, auto_y);
                                }
                                T17.Enabled = false;
                            }
                            break;

                        default:
                            break;
                    }
                    System.Threading.Thread.Sleep(10);
                }
                //catch
                //{
                //    T5.Enabled = false;
                //    MessageBox.Show("数值超限！");
                //    return;
                // }
            }

        }

        private void VTDR6110_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            btnBack_Click(btnBack, e);
        }

        private void btnCleanTextBox1_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
        }
        bool SerialPortFlag = true;
        private void btnInitcom_Click(object sender, EventArgs e)
        {

        }
        private void mtLoadGamma_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();
            string strtmp = "";
            of.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; ;
            of.Title = "打开Gamma文件";

            if (of.ShowDialog() == DialogResult.OK)
            {
                //读取文本信息
                FileStream fs = new FileStream(of.FileName, FileMode.Open, FileAccess.Read);
                StreamReader streamReader = new StreamReader(fs, Encoding.GetEncoding("GBK"));
                streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
                string strLine = streamReader.ReadLine();
                //循环读取文本信息
                while (!string.IsNullOrEmpty(strLine))
                {
                    strtmp = strtmp + strLine + ",";
                    strLine = streamReader.ReadLine(); //循环读取下一行
                }
                fs.Close(); //关闭流
                streamReader.Close();

                string[] arrtmp = strtmp.Split(new Char[] { ',' });

                //else if (IC_comboBox.SelectedIndex == 18) //VT VTDR6100
                {
                    VTDR6100_R0.Text = arrtmp[1].ToString(); VTDR6100_G0.Text = arrtmp[3].ToString(); VTDR6100_B0.Text = arrtmp[5].ToString();
                    VTDR6100_R1.Text = arrtmp[7].ToString(); VTDR6100_G1.Text = arrtmp[9].ToString(); VTDR6100_B1.Text = arrtmp[11].ToString();
                    VTDR6100_R3.Text = arrtmp[13].ToString(); VTDR6100_G3.Text = arrtmp[15].ToString(); VTDR6100_B3.Text = arrtmp[17].ToString();
                    VTDR6100_R5.Text = arrtmp[19].ToString(); VTDR6100_G5.Text = arrtmp[21].ToString(); VTDR6100_B5.Text = arrtmp[23].ToString();
                    VTDR6100_R7.Text = arrtmp[25].ToString(); VTDR6100_G7.Text = arrtmp[27].ToString(); VTDR6100_B7.Text = arrtmp[29].ToString();
                    VTDR6100_R11.Text = arrtmp[31].ToString(); VTDR6100_G11.Text = arrtmp[33].ToString(); VTDR6100_B11.Text = arrtmp[35].ToString();
                    VTDR6100_R15.Text = arrtmp[37].ToString(); VTDR6100_G15.Text = arrtmp[39].ToString(); VTDR6100_B15.Text = arrtmp[41].ToString();
                    VTDR6100_R19.Text = arrtmp[43].ToString(); VTDR6100_G19.Text = arrtmp[45].ToString(); VTDR6100_B19.Text = arrtmp[47].ToString();
                    VTDR6100_R23.Text = arrtmp[49].ToString(); VTDR6100_G23.Text = arrtmp[51].ToString(); VTDR6100_B23.Text = arrtmp[53].ToString();
                    VTDR6100_R27.Text = arrtmp[55].ToString(); VTDR6100_G27.Text = arrtmp[57].ToString(); VTDR6100_B27.Text = arrtmp[59].ToString();
                    VTDR6100_R31.Text = arrtmp[61].ToString(); VTDR6100_G31.Text = arrtmp[63].ToString(); VTDR6100_B31.Text = arrtmp[65].ToString();
                    VTDR6100_R35.Text = arrtmp[67].ToString(); VTDR6100_G35.Text = arrtmp[69].ToString(); VTDR6100_B35.Text = arrtmp[71].ToString();
                    VTDR6100_R39.Text = arrtmp[73].ToString(); VTDR6100_G39.Text = arrtmp[75].ToString(); VTDR6100_B39.Text = arrtmp[77].ToString();
                    VTDR6100_R47.Text = arrtmp[79].ToString(); VTDR6100_G47.Text = arrtmp[81].ToString(); VTDR6100_B47.Text = arrtmp[83].ToString();
                    VTDR6100_R55.Text = arrtmp[85].ToString(); VTDR6100_G55.Text = arrtmp[87].ToString(); VTDR6100_B55.Text = arrtmp[89].ToString();
                    VTDR6100_R63.Text = arrtmp[91].ToString(); VTDR6100_G63.Text = arrtmp[93].ToString(); VTDR6100_B63.Text = arrtmp[95].ToString();
                    VTDR6100_R71.Text = arrtmp[97].ToString(); VTDR6100_G71.Text = arrtmp[99].ToString(); VTDR6100_B71.Text = arrtmp[101].ToString();
                    VTDR6100_R79.Text = arrtmp[103].ToString(); VTDR6100_G79.Text = arrtmp[105].ToString(); VTDR6100_B79.Text = arrtmp[107].ToString();
                    VTDR6100_R95.Text = arrtmp[109].ToString(); VTDR6100_G95.Text = arrtmp[111].ToString(); VTDR6100_B95.Text = arrtmp[113].ToString();
                    VTDR6100_R111.Text = arrtmp[115].ToString(); VTDR6100_G111.Text = arrtmp[117].ToString(); VTDR6100_B111.Text = arrtmp[119].ToString();
                    VTDR6100_R127.Text = arrtmp[121].ToString(); VTDR6100_G127.Text = arrtmp[123].ToString(); VTDR6100_B127.Text = arrtmp[125].ToString();
                    VTDR6100_R159.Text = arrtmp[127].ToString(); VTDR6100_G159.Text = arrtmp[129].ToString(); VTDR6100_B159.Text = arrtmp[131].ToString();
                    VTDR6100_R191.Text = arrtmp[133].ToString(); VTDR6100_G191.Text = arrtmp[135].ToString(); VTDR6100_B191.Text = arrtmp[137].ToString();
                    VTDR6100_R223.Text = arrtmp[139].ToString(); VTDR6100_G223.Text = arrtmp[141].ToString(); VTDR6100_B223.Text = arrtmp[143].ToString();
                    VTDR6100_R255.Text = arrtmp[145].ToString(); VTDR6100_G255.Text = arrtmp[147].ToString(); VTDR6100_B255.Text = arrtmp[149].ToString();

                }


            }
        }

        private void mtSaveGamma_Click(object sender, EventArgs e)
        {
            SaveFileDialog sf = new SaveFileDialog(); //对话框
            sf.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; //定义保存的文件的类型
            string str = "保存Gamma文件";
            if (sf.ShowDialog() == DialogResult.OK) //如果确定保存
            {
                if (sf.FileName == "") return; //如果没有输入文件名
                try
                {
                    StreamWriter sw = null; //文件流
                    sw = new StreamWriter(sf.FileName, false, Encoding.UTF8);
                    //VTDR6100
                    {
                        str = str + "R0," + VTDR6100_R0.Text + "," + "G0," + VTDR6100_G0.Text + "," + "B0," + VTDR6100_B0.Text + "\r\n";
                        str = str + "R1," + VTDR6100_R1.Text + "," + "G1," + VTDR6100_G1.Text + "," + "B1," + VTDR6100_B1.Text + "\r\n";
                        str = str + "R3," + VTDR6100_R3.Text + "," + "G3," + VTDR6100_G3.Text + "," + "B3," + VTDR6100_B3.Text + "\r\n";
                        str = str + "R5," + VTDR6100_R5.Text + "," + "G5," + VTDR6100_G5.Text + "," + "B5," + VTDR6100_B5.Text + "\r\n";
                        str = str + "R7," + VTDR6100_R7.Text + "," + "G7," + VTDR6100_G7.Text + "," + "B7," + VTDR6100_B7.Text + "\r\n";
                        str = str + "R11," + VTDR6100_R11.Text + "," + "G11," + VTDR6100_G11.Text + "," + "B11," + VTDR6100_B11.Text + "\r\n";
                        str = str + "R15," + VTDR6100_R15.Text + "," + "G15," + VTDR6100_G15.Text + "," + "B15," + VTDR6100_B15.Text + "\r\n";
                        str = str + "R19," + VTDR6100_R19.Text + "," + "G19," + VTDR6100_G19.Text + "," + "B20," + VTDR6100_B19.Text + "\r\n";
                        str = str + "R23," + VTDR6100_R23.Text + "," + "G23," + VTDR6100_G23.Text + "," + "B23," + VTDR6100_B23.Text + "\r\n";
                        str = str + "R27," + VTDR6100_R27.Text + "," + "G27," + VTDR6100_G27.Text + "," + "B27," + VTDR6100_B27.Text + "\r\n";
                        str = str + "R31," + VTDR6100_R31.Text + "," + "G31," + VTDR6100_G31.Text + "," + "B31," + VTDR6100_B31.Text + "\r\n";
                        str = str + "R35," + VTDR6100_R35.Text + "," + "G35," + VTDR6100_G35.Text + "," + "B35," + VTDR6100_B35.Text + "\r\n";
                        str = str + "R39," + VTDR6100_R39.Text + "," + "G39," + VTDR6100_G39.Text + "," + "B39," + VTDR6100_B39.Text + "\r\n";
                        str = str + "R47," + VTDR6100_R47.Text + "," + "G47," + VTDR6100_G47.Text + "," + "B47," + VTDR6100_B47.Text + "\r\n";
                        str = str + "R55," + VTDR6100_R55.Text + "," + "G55," + VTDR6100_G55.Text + "," + "B55," + VTDR6100_B55.Text + "\r\n";
                        str = str + "R63," + VTDR6100_R63.Text + "," + "G63," + VTDR6100_G63.Text + "," + "B63," + VTDR6100_B63.Text + "\r\n";
                        str = str + "R71," + VTDR6100_R71.Text + "," + "G71," + VTDR6100_G71.Text + "," + "B71," + VTDR6100_B71.Text + "\r\n";
                        str = str + "R79," + VTDR6100_R79.Text + "," + "G79," + VTDR6100_G79.Text + "," + "B79," + VTDR6100_B79.Text + "\r\n";
                        str = str + "R95," + VTDR6100_R95.Text + "," + "G95," + VTDR6100_G95.Text + "," + "B95," + VTDR6100_B95.Text + "\r\n";
                        str = str + "R111," + VTDR6100_R111.Text + "," + "G111," + VTDR6100_G111.Text + "," + "B111," + VTDR6100_B111.Text + "\r\n";
                        str = str + "R127," + VTDR6100_R127.Text + "," + "G127," + VTDR6100_G127.Text + "," + "B127," + VTDR6100_B127.Text + "\r\n";
                        str = str + "R159," + VTDR6100_R159.Text + "," + "G159," + VTDR6100_G159.Text + "," + "B159," + VTDR6100_B159.Text + "\r\n";
                        str = str + "R191," + VTDR6100_R191.Text + "," + "G191," + VTDR6100_G191.Text + "," + "B191," + VTDR6100_B191.Text + "\r\n";
                        str = str + "R223," + VTDR6100_R223.Text + "," + "G223," + VTDR6100_G223.Text + "," + "B223," + VTDR6100_B223.Text + "\r\n";
                        str = str + "R255," + VTDR6100_R255.Text + "," + "G255," + VTDR6100_G255.Text + "," + "B255," + VTDR6100_B255.Text + "\r\n";
                        sw.WriteLine(str);
                    }

                    sw.Dispose(); //释放资源
                    sw.Close(); //关闭数据流
                    MessageBox.Show("Gamma保存OK！", "系统提示：");
                }
                catch
                {
                    MessageBox.Show("Gamma保存时发生错误，请再试！", "系统提示：");
                }
            }
        }
        private void btnCal_manual_MouseEnter(object sender, EventArgs e)
        {
            ToolTip p = new ToolTip();
            p.ShowAlways = true;
            p.SetToolTip(this.btnCal_manual, "CA310连接校准，自带黑画面，按下静候6秒");
        }

        private void btnBack_MouseEnter(object sender, EventArgs e)
        {
            ToolTip p = new ToolTip();
            p.ShowAlways = true;
            p.SetToolTip(this.btnBack, "返回屏体初始化设定界面");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;
            Int32 DataNum;

            VTDR6100_txtRegData.Text = "f0,aa,13";

            string strLine = Convert.ToString(VTDR6100_txtRegData.Text);
            string[] arr = strLine.Split(','); //以逗号分割，添加到数组


            {
                Setting.TempRecord.cmdLen = arr.Length + 5;
                Send_buf = new byte[arr.Length + 5];
                Send_buf[0] = 0x4D;//VTDR6100

                //if (VTDR6100_rbt_LP.Checked == true)
                { Send_buf[1] = 0x01; }
                //else if (VTDR6100_rbt_HS.Checked == true)
                //{ Send_buf[1] = 0x81; }

                Send_buf[2] = byte.Parse(arr.Length.ToString());
                for (int i = 0; i < arr.Length; i++)
                {
                    Send_buf[3 + i] = byte.Parse((Convert.ToInt32(arr[i], 16)).ToString());
                }
                CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + arr.Length - 2], out Send_buf[5 + arr.Length - 1]);
                try
                {
                    MainForm.comPort.Write(Send_buf, 0, 5 + arr.Length);
                }
                catch
                {
                    MessageBox.Show("串口有误，请检查", "错误");
                }
            }
            Thread.Sleep(100);
            VTDR6100_txtRegData.Text = "bf,00";

            strLine = Convert.ToString(VTDR6100_txtRegData.Text);
            arr = strLine.Split(','); //以逗号分割，添加到数组


            {
                Setting.TempRecord.cmdLen = arr.Length + 5;
                Send_buf = new byte[arr.Length + 5];
                Send_buf[0] = 0x4D;//VTDR6100

                //if (VTDR6100_rbt_LP.Checked == true)
                { Send_buf[1] = 0x01; }
                //else if (VTDR6100_rbt_HS.Checked == true)
                //{ Send_buf[1] = 0x81; }

                Send_buf[2] = 0x02;
                Send_buf[3 + 0] = 0xbf;
                Send_buf[3 + 1] = Convert.ToByte(VTDR6100_Gamma_Group.Value);
                //Send_buf[3 + 1] = byte.Parse((Convert.ToInt32(VTDR6100_Gamma_Group.Value)));
                //    for (int i = 0; i < arr.Length; i++)
                {
                    //       Send_buf[3 + i] = byte.Parse((Convert.ToInt32(arr[i], 16)).ToString());
                }
                CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + arr.Length - 2], out Send_buf[5 + arr.Length - 1]);
                try
                {
                    MainForm.comPort.Write(Send_buf, 0, 5 + arr.Length);
                }
                catch
                {
                    MessageBox.Show("串口有误，请检查", "错误");
                }
            }



            T1.Enabled = false;
            T1.Interval = 2000;
            T1.Enabled = true;
        }

        private void groupBox131_Enter(object sender, EventArgs e)
        {

        }

        private void btnVTStop_Click(object sender, EventArgs e)
        {
            T17.Enabled = false;
            flag1 = 1;
            flag2 = 1;
            flag3 = 1;
            adjust_Rnum = 0;
            adjust_Gnum = 0;
            adjust_Bnum = 0;
            adjust_l = 0;
            adjust_x = 0;
            adjust_y = 0;
        }

        private void VTDR6110_VisibleChanged(object sender, EventArgs e)
        {
            if (this.Visible == true) //子窗体已开启标识
            {
                MainForm.comPort.Close();
                Thread.Sleep(5);
                MainForm.comPort.DataReceived -= new SerialDataReceivedEventHandler(MainForm.SerialPort1_DataReceived);

                Thread.Sleep(5);
                MainForm.comPort.DataReceived += new SerialDataReceivedEventHandler(SerialPort1_DataReceived);
                Thread.Sleep(5);
                MainForm.comPort.Open();
                textBox1.Text += "com 已经连接！\r\n";
            }
            else
            {

            }
        }

        private void gamma_set_update(EventArgs e)
        {
            VTDR6100_GAMMA_Click(UP_READ_GAMMA, e);
            System.Threading.Thread.Sleep(100);
            VTDR6100_GAMMA_Click(UP_GREEN_GAMMA, e);
            System.Threading.Thread.Sleep(100);
            VTDR6100_GAMMA_Click(UP_BLUE_GAMMA, e);
            System.Threading.Thread.Sleep(100);
        }

        private void btnAutoGammas_VTDR6100_Click(object sender, EventArgs e)
        {
            int flag = 1;
            double Lr_d, Lg_d, Lb_d;

            gamma_set_update(e);

            D_lums = new double[14, 3];
            D_lum = new double[14];
            index = 0;
            adjust_Rnum = 0;
            adjust_Gnum = 0;
            adjust_Bnum = 0;
            adjust_l = 0;
            adjust_x = 0;
            adjust_y = 0;

            D_lum[0] = Convert.ToDouble(txtVT_255.Text);
            D_lum[1] = Convert.ToDouble(txtVT_223.Text);
            D_lum[2] = Convert.ToDouble(txtVT_191.Text);
            D_lum[3] = Convert.ToDouble(txtVT_127.Text);
            D_lum[4] = Convert.ToDouble(txtVT_111.Text);
            D_lum[5] = Convert.ToDouble(txtVT_79.Text);
            D_lum[6] = Convert.ToDouble(txtVT_63.Text);
            D_lum[7] = Convert.ToDouble(txtVT_55.Text);
            D_lum[8] = Convert.ToDouble(txtVT_47.Text);
            D_lum[9] = Convert.ToDouble(txtVT_39.Text);
            D_lum[10] = Convert.ToDouble(txtVT_35.Text);
            D_lum[11] = Convert.ToDouble(txtVT_31.Text);
            D_lum[12] = Convert.ToDouble(txtVT_11.Text);
            D_lum[13] = Convert.ToDouble(txtVT_3.Text);

            D_x = Convert.ToDouble(txtVT_x.Text);
            D_y = Convert.ToDouble(txtVT_y.Text);
            Lr_d = R_y * ((D_y - G_y) * (B_x - D_x) + (D_x - G_x) * (D_y - B_y)) / B_y / ((D_y - G_y) * (D_x - R_x) + (D_x - G_x) * (R_y - D_y));
            Lb_d = 1.0;
            Lg_d = G_y * ((D_y - R_y) * (B_x - D_x) + (D_x - R_x) * (D_y - B_y)) / B_y / ((D_y - R_y) * (D_x - G_x) + (D_x - R_x) * (G_y - D_y));

            for (int i = 0; i < 14; i++)
            {
                D_lums[i, 0] = D_lum[i] * Lr_d / (Lr_d + Lg_d + Lb_d);
                D_lums[i, 1] = D_lum[i] * Lg_d / (Lr_d + Lg_d + Lb_d);
                D_lums[i, 2] = D_lum[i] * Lb_d / (Lr_d + Lg_d + Lb_d);
            }

            switch (flag)
            {
                case 1://寄存器值与亮度正比
                    {
                        lum_off = Convert.ToDouble(txtVT_loff.Text);
                        x_off = Convert.ToDouble(txtVT_xoff.Text);
                        y_off = Convert.ToDouble(txtVT_yoff.Text);

                        VTDR6100_GAMMA_Click(VTDR6100_GammaW_Red, e);
                        VTDR6100_GAMMA_Click(VTDR6100_GammaW_Green, e);
                        VTDR6100_GAMMA_Click(VTDR6100_GammaW_Blue, e);

                        OLED_Show_Click(btnwhite, e);
                        T17.Enabled = true;
                    }
                    break;
                case 2:                                           //寄存器值与亮度反比
                    break;
                default:
                    break;
            }
        }

        private void btn6Gammas_VTDR6100_DLL_Click(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;
            int VT_Flag = 0;
            Class1 gma = new Class1();
            int[] Rcode = new int[13] {Convert.ToInt32(VTDR6100_R11.Text, 16),Convert.ToInt32(VTDR6100_R31.Text, 16),Convert.ToInt32(VTDR6100_R35.Text, 16),Convert.ToInt32(VTDR6100_R39.Text, 16),Convert.ToInt32(VTDR6100_R47.Text, 16),
                                       Convert.ToInt32(VTDR6100_R55.Text, 16), Convert.ToInt32(VTDR6100_R63.Text, 16) ,Convert.ToInt32(VTDR6100_R79.Text, 16),Convert.ToInt32(VTDR6100_R111.Text, 16), Convert.ToInt32(VTDR6100_R127.Text, 16) ,
                                       Convert.ToInt32(VTDR6100_R191.Text, 16),Convert.ToInt32(VTDR6100_R223.Text, 16),Convert.ToInt32(VTDR6100_R255.Text, 16) };

            int[] Gcode = new int[13] {Convert.ToInt32(VTDR6100_G11.Text, 16),Convert.ToInt32(VTDR6100_G31.Text, 16),Convert.ToInt32(VTDR6100_G35.Text, 16),Convert.ToInt32(VTDR6100_G39.Text, 16),Convert.ToInt32(VTDR6100_G47.Text, 16),
                                       Convert.ToInt32(VTDR6100_G55.Text, 16), Convert.ToInt32(VTDR6100_G63.Text, 16) ,Convert.ToInt32(VTDR6100_G79.Text, 16),Convert.ToInt32(VTDR6100_G111.Text, 16), Convert.ToInt32(VTDR6100_G127.Text, 16) ,
                                       Convert.ToInt32(VTDR6100_G191.Text, 16),Convert.ToInt32(VTDR6100_G223.Text, 16),Convert.ToInt32(VTDR6100_G255.Text, 16) };

            int[] Bcode = new int[13] {Convert.ToInt32(VTDR6100_B11.Text, 16),Convert.ToInt32(VTDR6100_B31.Text, 16),Convert.ToInt32(VTDR6100_B35.Text, 16),Convert.ToInt32(VTDR6100_B39.Text, 16),Convert.ToInt32(VTDR6100_B47.Text, 16),
                                       Convert.ToInt32(VTDR6100_B55.Text, 16), Convert.ToInt32(VTDR6100_B63.Text, 16) ,Convert.ToInt32(VTDR6100_B79.Text, 16),Convert.ToInt32(VTDR6100_B111.Text, 16), Convert.ToInt32(VTDR6100_B127.Text, 16) ,
                                       Convert.ToInt32(VTDR6100_B191.Text, 16),Convert.ToInt32(VTDR6100_B223.Text, 16),Convert.ToInt32(VTDR6100_B255.Text, 16)  };

            double[] Lcode = new double[13] { double.Parse(this.CAS200_dataGridView.Rows[12].Cells[3].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[11].Cells[3].Value.ToString()),double.Parse(this.CAS200_dataGridView.Rows[10].Cells[3].Value.ToString()),
                                              double.Parse(this.CAS200_dataGridView.Rows[9].Cells[3].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[8].Cells[3].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[7].Cells[3].Value.ToString()),
                                              double.Parse(this.CAS200_dataGridView.Rows[6].Cells[3].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[5].Cells[3].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[4].Cells[3].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[3].Cells[3].Value.ToString()),
                                              double.Parse(this.CAS200_dataGridView.Rows[2].Cells[3].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[1].Cells[3].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[0].Cells[3].Value.ToString()) };

            double[] xcode = new double[13] {double.Parse(this.CAS200_dataGridView.Rows[12].Cells[1].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[11].Cells[1].Value.ToString()),double.Parse(this.CAS200_dataGridView.Rows[10].Cells[1].Value.ToString()),
                                              double.Parse(this.CAS200_dataGridView.Rows[9].Cells[1].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[8].Cells[1].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[7].Cells[1].Value.ToString()),
                                              double.Parse(this.CAS200_dataGridView.Rows[6].Cells[1].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[5].Cells[1].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[4].Cells[1].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[3].Cells[1].Value.ToString()),
                                              double.Parse(this.CAS200_dataGridView.Rows[2].Cells[1].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[1].Cells[1].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[0].Cells[1].Value.ToString()) };

            double[] ycode = new double[13] {double.Parse(this.CAS200_dataGridView.Rows[12].Cells[2].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[11].Cells[2].Value.ToString()),double.Parse(this.CAS200_dataGridView.Rows[10].Cells[2].Value.ToString()),
                                              double.Parse(this.CAS200_dataGridView.Rows[9].Cells[2].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[8].Cells[2].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[7].Cells[2].Value.ToString()),
                                              double.Parse(this.CAS200_dataGridView.Rows[6].Cells[2].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[5].Cells[2].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[4].Cells[2].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[3].Cells[2].Value.ToString()),
                                              double.Parse(this.CAS200_dataGridView.Rows[2].Cells[2].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[1].Cells[2].Value.ToString()), double.Parse(this.CAS200_dataGridView.Rows[0].Cells[2].Value.ToString()) };

            int[,] RGB_Code = new int[3, 13];
            double[,] RGB_Lxy = new double[3, 13];

            for (int i = 0; i < 13; i++)
            {
                RGB_Code[0, i] = Rcode[i];
                RGB_Code[1, i] = Gcode[i];
                RGB_Code[2, i] = Bcode[i];

                RGB_Lxy[0, i] = Lcode[i];
                RGB_Lxy[1, i] = xcode[i];
                RGB_Lxy[2, i] = ycode[i];
            }
            int totalpoint = 13;
            int HBMmodebyGma = Convert.ToUInt16(text_HBMmodebyGma.Text);
            double NormalLum = Convert.ToDouble(text_NormalLum.Text);
            int LowLumbyGma = Convert.ToUInt16(text_LowLumbyGma.Text);
            int maxdbv = Convert.ToUInt16(text_Maxdbv.Text);

            //initail first
            //NormalLum is the luminance for dbv=255, HBMmodebyGma need to be set 1
            //gma.GMA_Tool_init(RGB_Code, RGB_Lxy, point5or6, NormalLum, HBMmodebyGma);
            gma.GMA_Tool_init(RGB_Code, RGB_Lxy, totalpoint, maxdbv, NormalLum, HBMmodebyGma, LowLumbyGma);

            int[,] GMA_CodeR = new int[9, 25];
            int[,] GMA_CodeG = new int[9, 25];
            int[,] GMA_CodeB = new int[9, 25];
            int[] dbvpoint = new int[11];
            int gmanumber = 0;

            int[,] GMA_CodeR22 = new int[9, 25];
            int[,] GMA_CodeG22 = new int[9, 25];
            int[,] GMA_CodeB22 = new int[9, 25];

            //for AOD luminance gamma code
            int codeR = 0, codeG = 0, codeB = 0;
            switch (btnTmp.Name)
            {
                case "VT_DLL_NORMAL":
                    {
                        gma.GMA_process(ref GMA_CodeR, ref GMA_CodeG, ref GMA_CodeB, ref dbvpoint, ref gmanumber);
                        VT_Flag = 1;
                    }
                    break;

                case "VT_Gamma2_2":
                    {
                        gma.GMA_process(ref GMA_CodeR, ref GMA_CodeG, ref GMA_CodeB, ref dbvpoint, ref gmanumber);
                        //use the same dbvpoint and gamma number
                        gma.GMA_process2_2(dbvpoint, gmanumber, ref GMA_CodeR22, ref GMA_CodeG22, ref GMA_CodeB22, maxdbv, NormalLum);
                        VT_Flag = 2;
                    }
                    break;
                case "VT_AOD_LUM":
                    {
                        gma.GMA_process(ref GMA_CodeR, ref GMA_CodeG, ref GMA_CodeB, ref dbvpoint, ref gmanumber);

                        gma.GMA_CodebyLum(30, ref codeR, ref codeG, ref codeB);
                        VT_Flag = 3;
                    }
                    break;

                default:
                    break;
            }

            if ((VT_Flag == 1) || (VT_Flag == 2) || (VT_Flag == 3))
            {
                SaveFileDialog sf = new SaveFileDialog(); //对话框
                sf.Filter = @"txt文件(*.txt)|*.txt|所有文件(*.*)|*.*"; //定义保存的文件的类型
                string str = "保存VT Driver IC Gamma Code文件";
                if (sf.ShowDialog() == DialogResult.OK) //如果确定保存
                {
                    if (sf.FileName == "") return; //如果没有输入文件名
                    StreamWriter sw = null; //文件流
                    sw = new StreamWriter(sf.FileName, false, Encoding.UTF8);
                    try
                    {
                        //printf 原始的初始化code
                        for (int i = 0; i < (MainForm.lstMIPIDriver.Items.Count - 2); i++)     //IC 初始化代码
                        {
                            str = MainForm.lstMIPIDriver.Items[i].ToString();
                            sw.WriteLine(str);
                        }
                        if (VT_Flag == 1)
                        {
                            str = "F0,AA,11";
                            sw.WriteLine(str);
                            str = "C3," + (dbvpoint[0] & 0xFF).ToString("X2") + "," + (dbvpoint[1] & 0xFF).ToString("X2") + "," + (dbvpoint[2] & 0xFF).ToString("X2") + ","
                                       + (dbvpoint[3] & 0xFF).ToString("X2") + "," + (dbvpoint[4] & 0xFF).ToString("X2") + "," + (dbvpoint[5] & 0xFF).ToString("X2") + ","
                                       + (dbvpoint[6] & 0xFF).ToString("X2") + "," + (dbvpoint[7] & 0xFF).ToString("X2") + "," + (dbvpoint[8] & 0xFF).ToString("X2") + ","
                                       + (dbvpoint[9] & 0xFF).ToString("X2") + "," + (dbvpoint[10] & 0xFF).ToString("X2") + ","
                                       + (((dbvpoint[0] & 0x100) >> 1) + ((dbvpoint[1] & 0x100) >> 2) + ((dbvpoint[2] & 0x100) >> 3) + ((dbvpoint[3] & 0x100) >> 4) + ((dbvpoint[4] & 0x100) >> 5)
                                       + ((dbvpoint[5] & 0x100) >> 6) + ((dbvpoint[6] & 0x100) >> 7) + ((dbvpoint[7] & 0x100) >> 8)).ToString("X2") + ","
                                       + (((dbvpoint[8] & 0x100) >> 6) + ((dbvpoint[9] & 0x100) >> 7) + ((dbvpoint[10] & 0x100) >> 8)).ToString("X2");
                            sw.WriteLine(str);

                            str = "F0,AA,13";
                            sw.WriteLine(str);

                            for (int i = 0; i <= 7; i++)
                            {
                                if ((i > gmanumber) && (i != 7))
                                    continue;

                                str = "BF," + i.ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma R
                                str = "B0,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeR[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                int leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B1,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeR[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B2,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeR[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B3," + ((GMA_CodeR[i, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[i, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma G
                                str = "B4,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeG[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B5,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeG[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B6,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeG[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B7," + ((GMA_CodeG[i, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[i, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma B
                                str = "B8,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeB[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B9,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeB[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "BA,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeB[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "BB," + ((GMA_CodeB[i, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[i, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);



                            }
                            if (HBMmodebyGma == 0)
                            {
                                str = "BF," + "08";
                                sw.WriteLine(str);

                                str = "B0,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeR[7, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[7, j] & 0xFF).ToString("X2") + ",";
                                }
                                int leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B1,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeR[7, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[7, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B2,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeR[7, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[7, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B3," + ((GMA_CodeR[7, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[7, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma G
                                str = "B4,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeG[7, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[7, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B5,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeG[7, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[7, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B6,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeG[7, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[7, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B7," + ((GMA_CodeG[7, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[7, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma B
                                str = "B8,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeB[7, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[7, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B9,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeB[7, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[7, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "BA,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeB[7, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[7, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "BB," + ((GMA_CodeB[7, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[7, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                            }
                            if (HBMmodebyGma == 1)
                            {
                                str = "BF," + "08";
                                sw.WriteLine(str);

                                str = "B0,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeR[8, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[8, j] & 0xFF).ToString("X2") + ",";
                                }
                                int leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B1,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeR[8, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[8, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B2,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeR[8, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[8, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B3," + ((GMA_CodeR[8, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR[8, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma G
                                str = "B4,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeG[8, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[8, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B5,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeG[8, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[8, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B6,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeG[8, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[8, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B7," + ((GMA_CodeG[8, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG[8, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma B
                                str = "B8,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeB[8, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[8, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "B9,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeB[8, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[8, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "BA,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeB[8, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[8, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng2 = str.Length;
                                str = str.Substring(0, leng2 - 1);
                                sw.WriteLine(str);

                                str = "BB," + ((GMA_CodeB[8, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB[8, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                            }
                            str = "11";
                            sw.WriteLine(str);
                            str = "29";
                            sw.WriteLine(str);
                            sw.Dispose(); //释放资源
                            sw.Close(); //关闭数据流
                            VT_Flag = 0;
                            MessageBox.Show("VT Driver IC Gamma Code保存OK！", "系统提示：");
                        }
                        else if (VT_Flag == 2)
                        {
                            str = "F0,AA,11";
                            sw.WriteLine(str);
                            str = "C3," + (dbvpoint[0] & 0xFF).ToString("X2") + "," + (dbvpoint[1] & 0xFF).ToString("X2") + "," + (dbvpoint[2] & 0xFF).ToString("X2") + ","
                                       + (dbvpoint[3] & 0xFF).ToString("X2") + "," + (dbvpoint[4] & 0xFF).ToString("X2") + "," + (dbvpoint[5] & 0xFF).ToString("X2") + ","
                                       + (dbvpoint[6] & 0xFF).ToString("X2") + "," + (dbvpoint[7] & 0xFF).ToString("X2") + "," + (dbvpoint[8] & 0xFF).ToString("X2") + ","
                                       + (dbvpoint[9] & 0xFF).ToString("X2") + "," + (dbvpoint[10] & 0xFF).ToString("X2") + ","
                                       + (((dbvpoint[0] & 0x100) >> 1) + ((dbvpoint[1] & 0x100) >> 2) + ((dbvpoint[2] & 0x100) >> 3) + ((dbvpoint[3] & 0x100) >> 4) + ((dbvpoint[4] & 0x100) >> 5)
                                       + ((dbvpoint[5] & 0x100) >> 6) + ((dbvpoint[6] & 0x100) >> 7) + ((dbvpoint[7] & 0x100) >> 8)).ToString("X2") + ","
                                       + (((dbvpoint[8] & 0x100) >> 6) + ((dbvpoint[9] & 0x100) >> 7) + ((dbvpoint[10] & 0x100) >> 8)).ToString("X2");
                            sw.WriteLine(str);

                            str = "F0,AA,13";
                            sw.WriteLine(str);

                            for (int i = 0; i <= 7; i++)
                            {
                                if ((i > gmanumber) && (i != 7))
                                    continue;

                                str = "BF," + i.ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma R
                                str = "B0,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeR22[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR22[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                int leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B1,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeR22[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR22[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B2,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeR22[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR22[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B3," + ((GMA_CodeR22[i, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeR22[i, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma G
                                str = "B4,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeG22[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG22[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B5,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeG22[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG22[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B6,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeG22[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG22[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B7," + ((GMA_CodeG22[i, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeG22[i, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                                //printf Gamma B
                                str = "B8,";
                                for (int j = 0; j < 8; j++)
                                {
                                    str = str + ((GMA_CodeB22[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB22[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "B9,";
                                for (int j = 8; j < 16; j++)
                                {
                                    str = str + ((GMA_CodeB22[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB22[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "BA,";
                                for (int j = 16; j < 24; j++)
                                {
                                    str = str + ((GMA_CodeB22[i, j] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB22[i, j] & 0xFF).ToString("X2") + ",";
                                }
                                leng = str.Length;
                                str = str.Substring(0, leng - 1);
                                sw.WriteLine(str);

                                str = "BB," + ((GMA_CodeB22[i, 24] & 0x300) >> 8).ToString("X2") + "," + (GMA_CodeB22[i, 24] & 0xFF).ToString("X2");
                                sw.WriteLine(str);

                            }
                            str = "11";
                            sw.WriteLine(str);
                            str = "29";
                            sw.WriteLine(str);
                            sw.Dispose(); //释放资源
                            sw.Close(); //关闭数据流
                            VT_Flag = 0;
                            MessageBox.Show("VT Driver IC Gamma Code保存OK！", "系统提示：");
                        }
                        else
                        {
                            str = "F0,AA,13";
                            sw.WriteLine(str);

                            str = "C0," + "00," + "00,";
                            str = str + ((codeR & 0x300) >> 8).ToString("X2") + "," + (codeR & 0xFF).ToString("X2") + ",";
                            str = str + "00," + "00," + "00," + "00";
                            sw.WriteLine(str);

                            str = "C1," + "00," + "00,";
                            str = str + ((codeG & 0x300) >> 8).ToString("X2") + "," + (codeG & 0xFF).ToString("X2") + ",";
                            str = str + "00," + "00," + "00," + "00";
                            sw.WriteLine(str);

                            str = "C2," + "00," + "00,";
                            str = str + ((codeB & 0x300) >> 8).ToString("X2") + "," + (codeB & 0xFF).ToString("X2") + ",";
                            str = str + "00," + "00," + "00," + "00";
                            sw.WriteLine(str);
                            str = "11";
                            sw.WriteLine(str);
                            str = "29";
                            sw.WriteLine(str);
                            sw.Dispose(); //释放资源
                            sw.Close(); //关闭数据流
                            VT_Flag = 0;
                            MessageBox.Show("VT Driver IC Gamma Code保存OK！", "系统提示：");

                        }

                    }
                    catch
                    {
                        MessageBox.Show("VT Driver IC Gamma Code保存时发生错误，请再试！", "系统提示：");
                    }
                }
            }
        }

        /*private void T12_Tick(object sender, EventArgs e)
        {
            double Lr_t, Lg_t, Lb_t, lumr, lumg, lumb;
            Msr_CA310();

            if ((auto_lum < (D_lum[index] + lum_off)) && (auto_lum > (D_lum[index] - lum_off)))//G
                flag1 = 0;
            if ((auto_y < (D_y + y_off)) && (auto_y > (D_y - y_off)) && flag1 == 0)//B
                flag2 = 0;
            if ((auto_x < (D_x + x_off)) && (auto_x > (D_x - x_off)) && flag1 == 0 && flag2 == 0)//R
                flag3 = 0;

            if (flag1 == 0 && flag2 == 0 && flag3 == 0)
            {
                T12.Enabled = false;
                index++;
                adjust_Rnum = 0;
                adjust_Gnum = 0;
                adjust_Bnum = 0;
                adjust_l = 0;
                adjust_x = 0;
                adjust_y = 0;
                if (index == 27)
                {
                    textBox1.Text = textBox1.Text + "RM69350 gamma调试完毕!\r\n";
                }
                if (index < 27)
                {
                    if ((adjust_class == "btnAutogamma350") && (adjust_num == 1))
                    {
                        switch (index)
                        {
                            case 1:
                                {
                                    rm350_R239.Value = rm350_R255.Value - 16;
                                    rm350_G239.Value = rm350_G255.Value - 16;
                                    rm350_B239.Value = rm350_B255.Value - 16;
                                    lum_off = Convert.ToDouble(txt_350_239off.Text);
                                    auto_gamma_write(mygamma_r[26], Convert.ToUInt16(rm350_R239.Value), mygamma_g[26], Convert.ToUInt16(rm350_G239.Value), mygamma_b[26], Convert.ToUInt16(rm350_B239.Value));
                                }
                                break;
                            case 2:
                                {
                                    rm350_R223.Value = rm350_R239.Value - 16;
                                    rm350_G223.Value = rm350_G239.Value - 16;
                                    rm350_B223.Value = rm350_B239.Value - 16;
                                    lum_off = Convert.ToDouble(txt_350_223off.Text);
                                    auto_gamma_write(mygamma_r[25], Convert.ToUInt16(rm350_R223.Value), mygamma_g[25], Convert.ToUInt16(rm350_G223.Value), mygamma_b[25], Convert.ToUInt16(rm350_B223.Value));
                                }
                                break;
                            case 3:
                                {
                                    VTDR6100_R255.Value = rm350_R223.Value - 16;
                                    VTDR6100_G255.Value = rm350_G223.Value - 16;
                                    VTDR6100_B255.Value = rm350_B223.Value - 16;
                                    lum_off = Convert.ToDouble((txt_350_207off.Text));
                                    auto_gamma_write(mygamma_r[24], Convert.ToUInt16(VTDR6100_R255.Value), mygamma_g[24], Convert.ToUInt16(VTDR6100_G255.Value), mygamma_b[24], Convert.ToUInt16(VTDR6100_B255.Value));
                                }
                                break;
                            case 4:
                                {
                                    VTDR6100_R223.Value = VTDR6100_R255.Value - 16;
                                    VTDR6100_G223.Value = VTDR6100_G255.Value - 16;
                                    VTDR6100_B223.Value = VTDR6100_B255.Value - 16;
                                    lum_off = Convert.ToDouble(txt_350_191off.Text);
                                    auto_gamma_write(mygamma_r[23], Convert.ToUInt16(VTDR6100_R223.Value), mygamma_g[23], Convert.ToUInt16(VTDR6100_G223.Value), mygamma_b[23], Convert.ToUInt16(VTDR6100_B223.Value));
                                }
                                break;
                            case 5:
                                {
                                    VTDR6100_R191.Value = VTDR6100_R223.Value - 32;
                                    VTDR6100_G191.Value = VTDR6100_G223.Value - 32;
                                    VTDR6100_B191.Value = VTDR6100_B223.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_175off.Text);
                                    auto_gamma_write(mygamma_r[22], Convert.ToUInt16(VTDR6100_R191.Value), mygamma_g[22], Convert.ToUInt16(VTDR6100_G191.Value), mygamma_b[22], Convert.ToUInt16(VTDR6100_B191.Value));
                                }
                                break;
                            case 6:
                                {
                                    VTDR6100_R159.Value = VTDR6100_R191.Value - 32;
                                    VTDR6100_G159.Value = VTDR6100_G191.Value - 32;
                                    VTDR6100_B159.Value = VTDR6100_B191.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_159off.Text);
                                    auto_gamma_write(mygamma_r[21], Convert.ToUInt16(VTDR6100_R159.Value), mygamma_g[21], Convert.ToUInt16(VTDR6100_G159.Value), mygamma_b[21], Convert.ToUInt16(VTDR6100_B159.Value));
                                }
                                break;
                            case 7:
                                {
                                    VTDR6100_R127.Value = VTDR6100_R159.Value - 32;
                                    VTDR6100_G127.Value = VTDR6100_G159.Value - 32;
                                    VTDR6100_B127.Value = VTDR6100_B159.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_143off.Text);
                                    auto_gamma_write(mygamma_r[20], Convert.ToUInt16(VTDR6100_R127.Value), mygamma_g[20], Convert.ToUInt16(VTDR6100_G127.Value), mygamma_b[20], Convert.ToUInt16(VTDR6100_B127.Value));
                                }
                                break;
                            case 8:
                                {
                                    VTDR6100_R111.Value = VTDR6100_R127.Value - 32;
                                    VTDR6100_G111.Value = VTDR6100_G127.Value - 32;
                                    VTDR6100_B111.Value = VTDR6100_B127.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_127off.Text);
                                    auto_gamma_write(mygamma_r[19], Convert.ToUInt16(VTDR6100_R111.Value), mygamma_g[19], Convert.ToUInt16(VTDR6100_G111.Value), mygamma_b[19], Convert.ToUInt16(VTDR6100_B111.Value));
                                }
                                break;
                            case 9:
                                {
                                    VTDR6100_R95.Value = VTDR6100_R111.Value - 32;
                                    VTDR6100_G95.Value = VTDR6100_G111.Value - 32;
                                    VTDR6100_B95.Value = VTDR6100_B111.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_111off.Text);
                                    auto_gamma_write(mygamma_r[18], Convert.ToUInt16(VTDR6100_R95.Value), mygamma_g[18], Convert.ToUInt16(VTDR6100_G95.Value), mygamma_b[18], Convert.ToUInt16(VTDR6100_B95.Value));
                                }
                                break;
                            case 10:
                                {
                                    VTDR6100_R79.Value = VTDR6100_R95.Value - 32;
                                    VTDR6100_G79.Value = VTDR6100_G95.Value - 32;
                                    VTDR6100_B79.Value = VTDR6100_B95.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_95off.Text);
                                    auto_gamma_write(mygamma_r[17], Convert.ToUInt16(VTDR6100_R79.Value), mygamma_g[17], Convert.ToUInt16(VTDR6100_G79.Value), mygamma_b[17], Convert.ToUInt16(VTDR6100_B79.Value));
                                }
                                break;
                            case 11:
                                {
                                    VTDR6100_R71.Value = VTDR6100_R79.Value - 32;
                                    VTDR6100_G71.Value = VTDR6100_G79.Value - 32;
                                    VTDR6100_B71.Value = VTDR6100_B79.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_79off.Text);
                                    auto_gamma_write(mygamma_r[16], Convert.ToUInt16(VTDR6100_R71.Value), mygamma_g[16], Convert.ToUInt16(VTDR6100_G71.Value), mygamma_b[16], Convert.ToUInt16(VTDR6100_B71.Value));
                                }
                                break;
                            case 12:
                                {
                                    VTDR6100_R63.Value = VTDR6100_R71.Value - 32;
                                    VTDR6100_G63.Value = VTDR6100_G71.Value - 32;
                                    VTDR6100_B63.Value = VTDR6100_B71.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_63off.Text);
                                    auto_gamma_write(mygamma_r[15], Convert.ToUInt16(VTDR6100_R63.Value), mygamma_g[15], Convert.ToUInt16(VTDR6100_G63.Value), mygamma_b[15], Convert.ToUInt16(VTDR6100_B63.Value));
                                }
                                break;
                            case 13:
                                {
                                    VTDR6100_R55.Value = VTDR6100_R63.Value - 32;
                                    VTDR6100_G55.Value = VTDR6100_G63.Value - 32;
                                    VTDR6100_B55.Value = VTDR6100_B63.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_55off.Text);
                                    auto_gamma_write(mygamma_r[14], Convert.ToUInt16(VTDR6100_R55.Value), mygamma_g[14], Convert.ToUInt16(VTDR6100_G55.Value), mygamma_b[14], Convert.ToUInt16(VTDR6100_B55.Value));
                                }
                                break;
                            case 14:
                                {
                                    VTDR6100_R47.Value = VTDR6100_R55.Value - 32;
                                    VTDR6100_G47.Value = VTDR6100_G55.Value - 32;
                                    VTDR6100_B47.Value = VTDR6100_B55.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_47off.Text);
                                    auto_gamma_write(mygamma_r[13], Convert.ToUInt16(VTDR6100_R47.Value), mygamma_g[13], Convert.ToUInt16(VTDR6100_G47.Value), mygamma_b[14], Convert.ToUInt16(VTDR6100_B47.Value));
                                }
                                break;
                            case 15:
                                {
                                    VTDR6100_R39.Value = VTDR6100_R47.Value - 32;
                                    VTDR6100_G39.Value = VTDR6100_G47.Value - 32;
                                    VTDR6100_B39.Value = VTDR6100_B47.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_39off.Text);
                                    auto_gamma_write(mygamma_r[12], Convert.ToUInt16(VTDR6100_R39.Value), mygamma_g[12], Convert.ToUInt16(VTDR6100_G39.Value), mygamma_b[12], Convert.ToUInt16(VTDR6100_B39.Value));
                                }
                                break;
                            case 16:
                                {
                                    VTDR6100_R35.Value = VTDR6100_R39.Value - 32;
                                    VTDR6100_G35.Value = VTDR6100_G39.Value - 32;
                                    VTDR6100_B35.Value = VTDR6100_B39.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_35off.Text);
                                    auto_gamma_write(mygamma_r[11], Convert.ToUInt16(VTDR6100_R35.Value), mygamma_g[11], Convert.ToUInt16(VTDR6100_G35.Value), mygamma_b[11], Convert.ToUInt16(VTDR6100_B35.Value));
                                }
                                break;
                            case 17:
                                {
                                    VTDR6100_R31.Value = VTDR6100_R35.Value - 32;
                                    VTDR6100_G31.Value = VTDR6100_G35.Value - 32;
                                    VTDR6100_B31.Value = VTDR6100_B35.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_31off.Text);
                                    auto_gamma_write(mygamma_r[10], Convert.ToUInt16(VTDR6100_R31.Value), mygamma_g[10], Convert.ToUInt16(VTDR6100_G31.Value), mygamma_b[10], Convert.ToUInt16(VTDR6100_B31.Value));
                                }
                                break;
                            case 18:
                                {
                                    VTDR6100_R27.Value = VTDR6100_R31.Value - 32;
                                    VTDR6100_G27.Value = VTDR6100_G31.Value - 32;
                                    VTDR6100_B27.Value = VTDR6100_B31.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_27off.Text);
                                    auto_gamma_write(mygamma_r[9], Convert.ToUInt16(VTDR6100_R27.Value), mygamma_g[9], Convert.ToUInt16(VTDR6100_G27.Value), mygamma_b[9], Convert.ToUInt16(VTDR6100_B27.Value));
                                }
                                break;
                            case 19:
                                {
                                    VTDR6100_R23.Value = VTDR6100_R27.Value - 32;
                                    VTDR6100_G23.Value = VTDR6100_G27.Value - 32;
                                    VTDR6100_B23.Value = VTDR6100_B27.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_23off.Text);
                                    auto_gamma_write(mygamma_r[8], Convert.ToUInt16(VTDR6100_R23.Value), mygamma_g[8], Convert.ToUInt16(VTDR6100_G23.Value), mygamma_b[8], Convert.ToUInt16(VTDR6100_B23.Value));
                                }
                                break;
                            case 20:
                                {
                                    VTDR6100_R19.Value = VTDR6100_R23.Value - 32;
                                    VTDR6100_G19.Value = VTDR6100_G23.Value - 32;
                                    VTDR6100_B19.Value = VTDR6100_B23.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_19off.Text);
                                    auto_gamma_write(mygamma_r[7], Convert.ToUInt16(VTDR6100_R19.Value), mygamma_g[7], Convert.ToUInt16(VTDR6100_G19.Value), mygamma_b[7], Convert.ToUInt16(VTDR6100_B19.Value));
                                }
                                break;
                            case 21:
                                {
                                    VTDR6100_R15.Value = VTDR6100_R19.Value - 32;
                                    VTDR6100_G15.Value = VTDR6100_G19.Value - 32;
                                    VTDR6100_B15.Value = VTDR6100_B19.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_15off.Text);
                                    auto_gamma_write(mygamma_r[6], Convert.ToUInt16(VTDR6100_R15.Value), mygamma_g[6], Convert.ToUInt16(VTDR6100_G15.Value), mygamma_b[6], Convert.ToUInt16(VTDR6100_B15.Value));
                                }
                                break;
                            case 22:
                                {
                                    VTDR6100_R11.Value = VTDR6100_R15.Value - 32;
                                    VTDR6100_G11.Value = VTDR6100_G15.Value - 32;
                                    VTDR6100_B11.Value = VTDR6100_B15.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_11off.Text);
                                    auto_gamma_write(mygamma_r[5], Convert.ToUInt16(VTDR6100_R11.Value), mygamma_g[5], Convert.ToUInt16(VTDR6100_G11.Value), mygamma_b[5], Convert.ToUInt16(VTDR6100_B11.Value));
                                }
                                break;
                            case 23:
                                {
                                    VTDR6100_R7.Value = VTDR6100_R11.Value - 32;
                                    VTDR6100_G7.Value = VTDR6100_G11.Value - 32;
                                    VTDR6100_B7.Value = VTDR6100_B11.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_7off.Text);
                                    auto_gamma_write(mygamma_r[4], Convert.ToUInt16(VTDR6100_R7.Value), mygamma_g[4], Convert.ToUInt16(VTDR6100_G7.Value), mygamma_b[4], Convert.ToUInt16(VTDR6100_B7.Value));
                                }
                                break;
                            case 24:
                                {
                                    VTDR6100_R5.Value = VTDR6100_R7.Value - 32;
                                    VTDR6100_G5.Value = VTDR6100_G7.Value - 32;
                                    VTDR6100_B5.Value = VTDR6100_B7.Value - 32;
                                    lum_off = Convert.ToDouble(txt_350_3off.Text);
                                    auto_gamma_write(mygamma_r[3], Convert.ToUInt16(VTDR6100_R5.Value), mygamma_g[3], Convert.ToUInt16(VTDR6100_G5.Value), mygamma_b[3], Convert.ToUInt16(VTDR6100_B5.Value));
                                }
                                break;

                        }
                    }
                    else
                    {
                        switch (index)
                        {
                            case 1:
                                lum_off = Convert.ToDouble(txt_350_239off.Text);
                                break;
                            case 2:
                                lum_off = Convert.ToDouble(txt_350_223off.Text);
                                break;
                            case 3:
                                lum_off = Convert.ToDouble(txt_350_207off.Text);
                                break;
                            case 4:
                                lum_off = Convert.ToDouble(txt_350_191off.Text);
                                break;
                            case 5:
                                lum_off = Convert.ToDouble(txt_350_175off.Text);
                                break;
                            case 6:
                                lum_off = Convert.ToDouble(txt_350_159off.Text);
                                break;
                            case 7:
                                lum_off = Convert.ToDouble(txt_350_143off.Text);
                                break;
                            case 8:
                                lum_off = Convert.ToDouble(txt_350_127off.Text) * Convert.ToDouble(txt_350_127.Text) / 100;
                                break;
                            case 9:
                                lum_off = Convert.ToDouble(txt_350_111off.Text) * Convert.ToDouble(txt_350_111.Text) / 100;
                                break;
                            case 10:
                                lum_off = Convert.ToDouble(txt_350_95off.Text) * Convert.ToDouble(txt_350_95.Text) / 100;
                                break;
                            case 11:
                                lum_off = Convert.ToDouble(txt_350_79off.Text) * Convert.ToDouble(txt_350_79.Text) / 100;
                                break;
                            case 12:
                                lum_off = Convert.ToDouble(txt_350_63off.Text) * Convert.ToDouble(txt_350_63.Text) / 100;
                                break;
                            case 13:
                                lum_off = Convert.ToDouble(txt_350_55off.Text) * Convert.ToDouble(txt_350_55.Text) / 100;
                                break;
                            case 14:
                                lum_off = Convert.ToDouble(txt_350_47off.Text) * Convert.ToDouble(txt_350_47.Text) / 100;
                                break;
                            case 15:
                                lum_off = Convert.ToDouble(txt_350_39off.Text) * Convert.ToDouble(txt_350_39.Text) / 100;
                                break;
                            case 16:
                                lum_off = Convert.ToDouble(txt_350_35off.Text) * Convert.ToDouble(txt_350_35.Text) / 100;
                                break;
                            case 17:
                                lum_off = Convert.ToDouble(txt_350_31off.Text) * Convert.ToDouble(txt_350_31.Text) / 100;
                                break;
                            case 18:
                                lum_off = Convert.ToDouble(txt_350_27off.Text) * Convert.ToDouble(txt_350_27.Text) / 100;
                                break;
                            case 19:
                                lum_off = Convert.ToDouble(txt_350_23off.Text) * Convert.ToDouble(txt_350_23.Text) / 100;
                                break;
                            case 20:
                                lum_off = Convert.ToDouble(txt_350_19off.Text) * Convert.ToDouble(txt_350_19.Text) / 100;
                                break;
                            case 21:
                                {
                                    lum_off = Convert.ToDouble(txt_350_15off.Text) * Convert.ToDouble(txt_350_15.Text) / 100;
                                    x_off = x_off + 0.001;
                                    y_off = y_off + 0.001;
                                }
                                break;
                            case 22:
                                {
                                    lum_off = Convert.ToDouble(txt_350_11off.Text) * Convert.ToDouble(txt_350_11.Text) / 100;
                                    x_off = x_off + 0.001;
                                    y_off = y_off + 0.001;
                                }
                                break;
                            case 23:
                                {
                                    lum_off = Convert.ToDouble(txt_350_7off.Text) * Convert.ToDouble(txt_350_7.Text) / 100;
                                    x_off = x_off + 0.001;
                                    y_off = y_off + 0.001;
                                }
                                break;
                            case 24:
                                {
                                    lum_off = Convert.ToDouble(txt_350_3off.Text) * Convert.ToDouble(txt_350_3.Text) / 100;
                                    x_off = x_off + 0.001;
                                    y_off = y_off + 0.001;
                                }
                                break;
                            case 25:
                                {
                                    lum_off = Convert.ToDouble(txt_350_2off.Text) * Convert.ToDouble(txt_350_2.Text) / 100;
                                    x_off = x_off + 0.001;
                                    y_off = y_off + 0.001;
                                }
                                break;
                            case 26:
                                {
                                    lum_off = Convert.ToDouble(txt_350_1off.Text) * Convert.ToDouble(txt_350_1.Text) / 100;
                                    x_off = x_off + 0.001;
                                    y_off = y_off + 0.001;
                                }
                                break;
                        }
                    }

                    numPatternR.Value = Parttern_RM67350[index];
                    numPatternG.Value = Parttern_RM67350[index];
                    numPatternB.Value = Parttern_RM67350[index];
                    //MainForm.LCD_Cfg_Click(btnPatternW, e);//写入Pattern参数
                    OLED_Show_Click(btnPatternW, null);
                    Thread.Sleep(10); //1秒=1000毫秒，
                    T12.Enabled = true;
                    flag1 = 1;
                    flag2 = 1;
                    flag3 = 1;
                }
            }
            else
            {
                Lr_t = R_y * ((auto_y - G_y) * (B_x - auto_x) + (auto_x - G_x) * (auto_y - B_y)) / B_y / ((auto_y - G_y) * (auto_x - R_x) + (auto_x - G_x) * (R_y - auto_y));
                Lb_t = 1.0;
                Lg_t = G_y * ((auto_y - R_y) * (B_x - auto_x) + (auto_x - R_x) * (auto_y - B_y)) / B_y / ((auto_y - R_y) * (auto_x - G_x) + (auto_x - R_x) * (G_y - auto_y));
                lumr = auto_lum * Lr_t / (Lr_t + Lg_t + Lb_t);
                lumg = auto_lum * Lg_t / (Lr_t + Lg_t + Lb_t);
                lumb = auto_lum * Lb_t / (Lr_t + Lg_t + Lb_t);

                switch (index)
                {
                    case 0:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm350_R255.Value = rm350_R255.Value - step_h;
                                    else rm350_R255.Value = rm350_R255.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm350_R255.Value = rm350_R255.Value - step_l;
                                    else rm350_R255.Value = rm350_R255.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm350_G255.Value = rm350_G255.Value - step_h;
                                    else rm350_G255.Value = rm350_G255.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm350_G255.Value = rm350_G255.Value - step_l;
                                    else rm350_G255.Value = rm350_G255.Value + step_l;
                                }
                                adjust_Gnum++;

                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm350_B255.Value = rm350_B255.Value - step_h;
                                    else rm350_B255.Value = rm350_B255.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm350_B255.Value = rm350_B255.Value - step_l;
                                    else rm350_B255.Value = rm350_B255.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[27], Convert.ToUInt16(rm350_R255.Value), mygamma_g[27], Convert.ToUInt16(rm350_G255.Value), mygamma_b[27], Convert.ToUInt16(rm350_B255.Value));
                        }
                        break;
                    case 1:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm350_R239.Value = rm350_R239.Value - step_h;
                                    else rm350_R239.Value = rm350_R239.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm350_R239.Value = rm350_R239.Value - step_l;
                                    else rm350_R239.Value = rm350_R239.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm350_G239.Value = rm350_G239.Value - step_h;
                                    else rm350_G239.Value = rm350_G239.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm350_G239.Value = rm350_G239.Value - step_l;
                                    else rm350_G239.Value = rm350_G239.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm350_B239.Value = rm350_B239.Value - step_h;
                                    else rm350_B239.Value = rm350_B239.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm350_B239.Value = rm350_B239.Value - step_l;
                                    else rm350_B239.Value = rm350_B239.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[26], Convert.ToUInt16(rm350_R239.Value), mygamma_g[26], Convert.ToUInt16(rm350_G239.Value), mygamma_b[26], Convert.ToUInt16(rm350_B239.Value));
                        }
                        break;
                    case 2:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm350_R223.Value = rm350_R223.Value - step_h;
                                    else rm350_R223.Value = rm350_R223.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm350_R223.Value = rm350_R223.Value - step_l;
                                    else rm350_R223.Value = rm350_R223.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm350_G223.Value = rm350_G223.Value - step_h;
                                    else rm350_G223.Value = rm350_G223.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm350_G223.Value = rm350_G223.Value - step_l;
                                    else rm350_G223.Value = rm350_G223.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm350_B223.Value = rm350_B223.Value - step_h;
                                    else rm350_B223.Value = rm350_B223.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm350_B223.Value = rm350_B223.Value - step_l;
                                    else rm350_B223.Value = rm350_B223.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[25], Convert.ToUInt16(rm350_R223.Value), mygamma_g[25], Convert.ToUInt16(rm350_G223.Value), mygamma_b[25], Convert.ToUInt16(rm350_B223.Value));
                        }
                        break;
                    case 3:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R255.Value = VTDR6100_R255.Value - step_h;
                                    else VTDR6100_R255.Value = VTDR6100_R255.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R255.Value = VTDR6100_R255.Value - step_l;
                                    else VTDR6100_R255.Value = VTDR6100_R255.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G255.Value = VTDR6100_G255.Value - step_h;
                                    else VTDR6100_G255.Value = VTDR6100_G255.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G255.Value = VTDR6100_G255.Value - step_l;
                                    else VTDR6100_G255.Value = VTDR6100_G255.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B255.Value = VTDR6100_B255.Value - step_h;
                                    else VTDR6100_B255.Value = VTDR6100_B255.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B255.Value = VTDR6100_B255.Value - step_l;
                                    else VTDR6100_B255.Value = VTDR6100_B255.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[24], Convert.ToUInt16(VTDR6100_R255.Value), mygamma_g[24], Convert.ToUInt16(VTDR6100_G255.Value), mygamma_b[24], Convert.ToUInt16(VTDR6100_B255.Value));
                        }
                        break;
                    case 4:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R223.Value = VTDR6100_R223.Value - step_h;
                                    else VTDR6100_R223.Value = VTDR6100_R223.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R223.Value = VTDR6100_R223.Value - step_l;
                                    else VTDR6100_R223.Value = VTDR6100_R223.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G223.Value = VTDR6100_G223.Value - step_h;
                                    else VTDR6100_G223.Value = VTDR6100_G223.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G223.Value = VTDR6100_G223.Value - step_l;
                                    else VTDR6100_G223.Value = VTDR6100_G223.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B223.Value = VTDR6100_B223.Value - step_h;
                                    else VTDR6100_B223.Value = VTDR6100_B223.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B223.Value = VTDR6100_B223.Value - step_l;
                                    else VTDR6100_B223.Value = VTDR6100_B223.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[23], Convert.ToUInt16(VTDR6100_R223.Value), mygamma_g[23], Convert.ToUInt16(VTDR6100_G223.Value), mygamma_b[23], Convert.ToUInt16(VTDR6100_B223.Value));
                        }
                        break;
                    case 5:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R191.Value = VTDR6100_R191.Value - step_h;
                                    else VTDR6100_R191.Value = VTDR6100_R191.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R191.Value = VTDR6100_R191.Value - step_l;
                                    else VTDR6100_R191.Value = VTDR6100_R191.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G191.Value = VTDR6100_G191.Value - step_h;
                                    else VTDR6100_G191.Value = VTDR6100_G191.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_R191.Value = VTDR6100_R191.Value - step_l;
                                    else VTDR6100_R191.Value = VTDR6100_R191.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B191.Value = VTDR6100_B191.Value - step_h;
                                    else VTDR6100_B191.Value = VTDR6100_B191.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B191.Value = VTDR6100_B191.Value - step_l;
                                    else VTDR6100_B191.Value = VTDR6100_B191.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[22], Convert.ToUInt16(VTDR6100_R191.Value), mygamma_g[22], Convert.ToUInt16(VTDR6100_G191.Value), mygamma_b[22], Convert.ToUInt16(VTDR6100_B191.Value));
                        }
                        break;
                    case 6:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R159.Value = VTDR6100_R159.Value - step_h;
                                    else VTDR6100_R159.Value = VTDR6100_R159.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R159.Value = VTDR6100_R159.Value - step_l;
                                    else VTDR6100_R159.Value = VTDR6100_R159.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G159.Value = VTDR6100_G159.Value - step_h;
                                    else VTDR6100_G159.Value = VTDR6100_G159.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G159.Value = VTDR6100_G159.Value - step_l;
                                    else VTDR6100_G159.Value = VTDR6100_G159.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B159.Value = VTDR6100_B159.Value - step_h;
                                    else VTDR6100_B159.Value = VTDR6100_B159.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B159.Value = VTDR6100_B159.Value - step_l;
                                    else VTDR6100_B159.Value = VTDR6100_B159.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[21], Convert.ToUInt16(VTDR6100_R159.Value), mygamma_g[21], Convert.ToUInt16(VTDR6100_G159.Value), mygamma_b[21], Convert.ToUInt16(VTDR6100_B159.Value));
                        }
                        break;
                    case 7:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R127.Value = VTDR6100_R127.Value - step_h;
                                    else VTDR6100_R127.Value = VTDR6100_R127.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R127.Value = VTDR6100_R127.Value - step_l;
                                    else VTDR6100_R127.Value = VTDR6100_R127.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G127.Value = VTDR6100_G127.Value - step_h;
                                    else VTDR6100_G127.Value = VTDR6100_G127.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G127.Value = VTDR6100_G127.Value - step_l;
                                    else VTDR6100_G127.Value = VTDR6100_G127.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B127.Value = VTDR6100_B127.Value - step_h;
                                    else VTDR6100_B127.Value = VTDR6100_B127.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B127.Value = VTDR6100_B127.Value - step_l;
                                    else VTDR6100_B127.Value = VTDR6100_B127.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[20], Convert.ToUInt16(VTDR6100_R127.Value), mygamma_g[20], Convert.ToUInt16(VTDR6100_G127.Value), mygamma_b[20], Convert.ToUInt16(VTDR6100_B127.Value));
                        }
                        break;
                    case 8:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R111.Value = VTDR6100_R111.Value - step_h;
                                    else VTDR6100_R111.Value = VTDR6100_R111.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R111.Value = VTDR6100_R111.Value - step_l;
                                    else VTDR6100_R111.Value = VTDR6100_R111.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G111.Value = VTDR6100_G111.Value - step_h;
                                    else VTDR6100_G111.Value = VTDR6100_G111.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G111.Value = VTDR6100_G111.Value - step_l;
                                    else VTDR6100_G111.Value = VTDR6100_G111.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B111.Value = VTDR6100_B111.Value - step_h;
                                    else VTDR6100_B111.Value = VTDR6100_B111.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B111.Value = VTDR6100_B111.Value - step_l;
                                    else VTDR6100_B111.Value = VTDR6100_B111.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[19], Convert.ToUInt16(VTDR6100_R111.Value), mygamma_g[19], Convert.ToUInt16(VTDR6100_G111.Value), mygamma_b[19], Convert.ToUInt16(VTDR6100_B111.Value));
                        }
                        break;
                    case 9:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R95.Value = VTDR6100_R95.Value - step_h;
                                    else VTDR6100_R95.Value = VTDR6100_R95.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R95.Value = VTDR6100_R95.Value - step_l;
                                    else VTDR6100_R95.Value = VTDR6100_R95.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G95.Value = VTDR6100_G95.Value - step_h;
                                    else VTDR6100_G95.Value = VTDR6100_G95.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G95.Value = VTDR6100_G95.Value - step_l;
                                    else VTDR6100_G95.Value = VTDR6100_G95.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B95.Value = VTDR6100_B95.Value - step_h;
                                    else VTDR6100_B95.Value = VTDR6100_B95.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B95.Value = VTDR6100_B95.Value - step_l;
                                    else VTDR6100_B95.Value = VTDR6100_B95.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[18], Convert.ToUInt16(VTDR6100_R95.Value), mygamma_g[18], Convert.ToUInt16(VTDR6100_G95.Value), mygamma_b[18], Convert.ToUInt16(VTDR6100_B95.Value));
                        }
                        break;
                    case 10:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R79.Value = VTDR6100_R79.Value - step_h;
                                    else VTDR6100_R79.Value = VTDR6100_R79.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R79.Value = VTDR6100_R79.Value - step_l;
                                    else VTDR6100_R79.Value = VTDR6100_R79.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G79.Value = VTDR6100_G79.Value - step_h;
                                    else VTDR6100_G79.Value = VTDR6100_G79.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G79.Value = VTDR6100_G79.Value - step_l;
                                    else VTDR6100_G79.Value = VTDR6100_G79.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B79.Value = VTDR6100_B79.Value - step_h;
                                    else VTDR6100_B79.Value = VTDR6100_B79.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B79.Value = VTDR6100_B79.Value - step_l;
                                    else VTDR6100_B79.Value = VTDR6100_B79.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[17], Convert.ToUInt16(VTDR6100_R79.Value), mygamma_g[17], Convert.ToUInt16(VTDR6100_G79.Value), mygamma_b[17], Convert.ToUInt16(VTDR6100_B79.Value));
                        }
                        break;
                    case 11:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R71.Value = VTDR6100_R71.Value - step_h;
                                    else VTDR6100_R71.Value = VTDR6100_R71.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R71.Value = VTDR6100_R71.Value - step_l;
                                    else VTDR6100_R71.Value = VTDR6100_R71.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G71.Value = VTDR6100_G71.Value - step_h;
                                    else VTDR6100_G71.Value = VTDR6100_G71.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G71.Value = VTDR6100_G71.Value - step_l;
                                    else VTDR6100_G71.Value = VTDR6100_G71.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B71.Value = VTDR6100_B71.Value - step_h;
                                    else VTDR6100_B71.Value = VTDR6100_B71.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B71.Value = VTDR6100_B71.Value - step_l;
                                    else VTDR6100_B71.Value = VTDR6100_B71.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[16], Convert.ToUInt16(VTDR6100_R71.Value), mygamma_g[16], Convert.ToUInt16(VTDR6100_G71.Value), mygamma_b[16], Convert.ToUInt16(VTDR6100_B71.Value));
                        }
                        break;
                    case 12:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R63.Value = VTDR6100_R63.Value - step_h;
                                    else VTDR6100_R63.Value = VTDR6100_R63.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R63.Value = VTDR6100_R63.Value - step_l;
                                    else VTDR6100_R63.Value = VTDR6100_R63.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G63.Value = VTDR6100_G63.Value - step_h;
                                    else VTDR6100_G63.Value = VTDR6100_G63.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G63.Value = VTDR6100_G63.Value - step_l;
                                    else VTDR6100_G63.Value = VTDR6100_G63.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B63.Value = VTDR6100_B63.Value - step_h;
                                    else VTDR6100_B63.Value = VTDR6100_B63.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B63.Value = VTDR6100_B63.Value - step_l;
                                    else VTDR6100_B63.Value = VTDR6100_B63.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[15], Convert.ToUInt16(VTDR6100_R63.Value), mygamma_g[15], Convert.ToUInt16(VTDR6100_G63.Value), mygamma_b[15], Convert.ToUInt16(VTDR6100_B63.Value));
                        }
                        break;
                    case 13:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R55.Value = VTDR6100_R55.Value - step_h;
                                    else VTDR6100_R55.Value = VTDR6100_R55.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R55.Value = VTDR6100_R55.Value - step_l;
                                    else VTDR6100_R55.Value = VTDR6100_R55.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G55.Value = VTDR6100_G55.Value - step_h;
                                    else VTDR6100_G55.Value = VTDR6100_G55.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G55.Value = VTDR6100_G55.Value - step_l;
                                    else VTDR6100_G55.Value = VTDR6100_G55.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B55.Value = VTDR6100_B55.Value - step_h;
                                    else VTDR6100_B55.Value = VTDR6100_B55.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B55.Value = VTDR6100_B55.Value - step_l;
                                    else VTDR6100_B55.Value = VTDR6100_B55.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[14], Convert.ToUInt16(VTDR6100_R55.Value), mygamma_g[14], Convert.ToUInt16(VTDR6100_G55.Value), mygamma_b[14], Convert.ToUInt16(VTDR6100_B55.Value));
                        }
                        break;
                    case 14:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R47.Value = VTDR6100_R47.Value - step_h;
                                    else VTDR6100_R47.Value = VTDR6100_R47.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R47.Value = VTDR6100_R47.Value - step_l;
                                    else VTDR6100_R47.Value = VTDR6100_R47.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G47.Value = VTDR6100_G47.Value - step_h;
                                    else VTDR6100_G47.Value = VTDR6100_G47.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G47.Value = VTDR6100_G47.Value - step_l;
                                    else VTDR6100_G47.Value = VTDR6100_G47.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B47.Value = VTDR6100_B47.Value - step_h;
                                    else VTDR6100_B47.Value = VTDR6100_B47.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B47.Value = VTDR6100_B47.Value - step_l;
                                    else VTDR6100_B47.Value = VTDR6100_B47.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[13], Convert.ToUInt16(VTDR6100_R47.Value), mygamma_g[13], Convert.ToUInt16(VTDR6100_G47.Value), mygamma_b[13], Convert.ToUInt16(VTDR6100_B47.Value));
                        }
                        break;
                    case 15:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R39.Value = VTDR6100_R39.Value - step_h;
                                    else VTDR6100_R39.Value = VTDR6100_R39.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R39.Value = VTDR6100_R39.Value - step_l;
                                    else VTDR6100_R39.Value = VTDR6100_R39.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G39.Value = VTDR6100_G39.Value - step_h;
                                    else VTDR6100_G39.Value = VTDR6100_G39.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G39.Value = VTDR6100_G39.Value - step_l;
                                    else VTDR6100_G39.Value = VTDR6100_G39.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B39.Value = VTDR6100_B39.Value - step_h;
                                    else VTDR6100_B39.Value = VTDR6100_B39.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B39.Value = VTDR6100_B39.Value - step_l;
                                    else VTDR6100_B39.Value = VTDR6100_B39.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[12], Convert.ToUInt16(VTDR6100_R39.Value), mygamma_g[12], Convert.ToUInt16(VTDR6100_G39.Value), mygamma_b[12], Convert.ToUInt16(VTDR6100_B39.Value));
                        }
                        break;
                    case 16:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R35.Value = VTDR6100_R35.Value - step_h;
                                    else VTDR6100_R35.Value = VTDR6100_R35.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R35.Value = VTDR6100_R35.Value - step_l;
                                    else VTDR6100_R35.Value = VTDR6100_R35.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G35.Value = VTDR6100_G35.Value - step_h;
                                    else VTDR6100_G35.Value = VTDR6100_G35.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G35.Value = VTDR6100_G35.Value - step_l;
                                    else VTDR6100_G35.Value = VTDR6100_G35.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B35.Value = VTDR6100_B35.Value - step_h;
                                    else VTDR6100_B35.Value = VTDR6100_B35.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B35.Value = VTDR6100_B35.Value - step_l;
                                    else VTDR6100_B35.Value = VTDR6100_B35.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[11], Convert.ToUInt16(VTDR6100_R35.Value), mygamma_g[11], Convert.ToUInt16(VTDR6100_G35.Value), mygamma_b[11], Convert.ToUInt16(VTDR6100_B35.Value));
                        }
                        break;
                    case 17:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R31.Value = VTDR6100_R31.Value - step_h;
                                    else VTDR6100_R31.Value = VTDR6100_R31.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R31.Value = VTDR6100_R31.Value - step_l;
                                    else VTDR6100_R31.Value = VTDR6100_R31.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G31.Value = VTDR6100_G31.Value - step_h;
                                    else VTDR6100_G31.Value = VTDR6100_G31.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G31.Value = VTDR6100_G31.Value - step_l;
                                    else VTDR6100_G31.Value = VTDR6100_G31.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B31.Value = VTDR6100_B31.Value - step_h;
                                    else VTDR6100_B31.Value = VTDR6100_B31.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B31.Value = VTDR6100_B31.Value - step_l;
                                    else VTDR6100_B31.Value = VTDR6100_B31.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[10], Convert.ToUInt16(VTDR6100_R31.Value), mygamma_g[10], Convert.ToUInt16(VTDR6100_G31.Value), mygamma_b[10], Convert.ToUInt16(VTDR6100_B31.Value));
                        }
                        break;
                    case 18:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R27.Value = VTDR6100_R27.Value - step_h;
                                    else VTDR6100_R27.Value = VTDR6100_R27.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R27.Value = VTDR6100_R27.Value - step_l;
                                    else VTDR6100_R27.Value = VTDR6100_R27.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G27.Value = VTDR6100_G27.Value - step_h;
                                    else VTDR6100_G27.Value = VTDR6100_G27.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G27.Value = VTDR6100_G27.Value - step_l;
                                    else VTDR6100_G27.Value = VTDR6100_G27.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B27.Value = VTDR6100_B27.Value - step_h;
                                    else VTDR6100_B27.Value = VTDR6100_B27.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B27.Value = VTDR6100_B27.Value - step_l;
                                    else VTDR6100_B27.Value = VTDR6100_B27.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[9], Convert.ToUInt16(VTDR6100_R27.Value), mygamma_g[9], Convert.ToUInt16(VTDR6100_G27.Value), mygamma_b[9], Convert.ToUInt16(VTDR6100_B27.Value));
                        }
                        break;
                    case 19:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R23.Value = VTDR6100_R23.Value - step_h;
                                    else VTDR6100_R23.Value = VTDR6100_R23.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R23.Value = VTDR6100_R23.Value - step_l;
                                    else VTDR6100_R23.Value = VTDR6100_R23.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G23.Value = VTDR6100_G23.Value - step_h;
                                    else VTDR6100_G23.Value = VTDR6100_G23.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G23.Value = VTDR6100_G23.Value - step_l;
                                    else VTDR6100_G23.Value = VTDR6100_G23.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B23.Value = VTDR6100_B23.Value - step_h;
                                    else VTDR6100_B23.Value = VTDR6100_B23.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B23.Value = VTDR6100_B23.Value - step_l;
                                    else VTDR6100_B23.Value = VTDR6100_B23.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[8], Convert.ToUInt16(VTDR6100_R23.Value), mygamma_g[8], Convert.ToUInt16(VTDR6100_G23.Value), mygamma_b[8], Convert.ToUInt16(VTDR6100_B23.Value));
                        }
                        break;
                    case 20:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R19.Value = VTDR6100_R19.Value - step_h;
                                    else VTDR6100_R19.Value = VTDR6100_R19.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R19.Value = VTDR6100_R19.Value - step_l;
                                    else VTDR6100_R19.Value = VTDR6100_R19.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G19.Value = VTDR6100_G19.Value - step_h;
                                    else VTDR6100_G19.Value = VTDR6100_G19.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G19.Value = VTDR6100_G19.Value - step_l;
                                    else VTDR6100_G19.Value = VTDR6100_G19.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B19.Value = VTDR6100_B19.Value - step_h;
                                    else VTDR6100_B19.Value = VTDR6100_B19.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B19.Value = VTDR6100_B19.Value - step_l;
                                    else VTDR6100_B19.Value = VTDR6100_B19.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[7], Convert.ToUInt16(VTDR6100_R19.Value), mygamma_g[7], Convert.ToUInt16(VTDR6100_G19.Value), mygamma_b[7], Convert.ToUInt16(VTDR6100_B19.Value));
                        }
                        break;
                    case 21:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R15.Value = VTDR6100_R15.Value - step_h;
                                    else VTDR6100_R15.Value = VTDR6100_R15.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R15.Value = VTDR6100_R15.Value - step_l;
                                    else VTDR6100_R15.Value = VTDR6100_R15.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G15.Value = VTDR6100_G15.Value - step_h;
                                    else VTDR6100_G15.Value = VTDR6100_G15.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G15.Value = VTDR6100_G15.Value - step_l;
                                    else VTDR6100_G15.Value = VTDR6100_G15.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B15.Value = VTDR6100_B15.Value - step_h;
                                    else VTDR6100_B15.Value = VTDR6100_B15.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B15.Value = VTDR6100_B15.Value - step_l;
                                    else VTDR6100_B15.Value = VTDR6100_B15.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[6], Convert.ToUInt16(VTDR6100_R15.Value), mygamma_g[6], Convert.ToUInt16(VTDR6100_G15.Value), mygamma_b[6], Convert.ToUInt16(VTDR6100_B15.Value));
                        }
                        break;
                    case 22:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R11.Value = VTDR6100_R11.Value - step_h;
                                    else VTDR6100_R11.Value = VTDR6100_R11.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R11.Value = VTDR6100_R11.Value - step_l;
                                    else VTDR6100_R11.Value = VTDR6100_R11.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G11.Value = VTDR6100_G11.Value - step_h;
                                    else VTDR6100_G11.Value = VTDR6100_G11.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G11.Value = VTDR6100_G11.Value - step_l;
                                    else VTDR6100_G11.Value = VTDR6100_G11.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B11.Value = VTDR6100_B11.Value - step_h;
                                    else VTDR6100_B11.Value = VTDR6100_B11.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B11.Value = VTDR6100_B11.Value - step_l;
                                    else VTDR6100_B11.Value = VTDR6100_B11.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[5], Convert.ToUInt16(VTDR6100_R11.Value), mygamma_g[5], Convert.ToUInt16(VTDR6100_G11.Value), mygamma_b[5], Convert.ToUInt16(VTDR6100_B11.Value));
                        }
                        break;
                    case 23:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R7.Value = VTDR6100_R7.Value - step_h;
                                    else VTDR6100_R7.Value = VTDR6100_R7.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R7.Value = VTDR6100_R7.Value - step_l;
                                    else VTDR6100_R7.Value = VTDR6100_R7.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G7.Value = VTDR6100_G7.Value - step_h;
                                    else VTDR6100_G7.Value = VTDR6100_G7.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G7.Value = VTDR6100_G7.Value - step_l;
                                    else VTDR6100_G7.Value = VTDR6100_G7.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B7.Value = VTDR6100_B7.Value - step_h;
                                    else VTDR6100_B7.Value = VTDR6100_B7.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B7.Value = VTDR6100_B7.Value - step_l;
                                    else VTDR6100_B7.Value = VTDR6100_B7.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[4], Convert.ToUInt16(VTDR6100_R7.Value), mygamma_g[4], Convert.ToUInt16(VTDR6100_G7.Value), mygamma_b[4], Convert.ToUInt16(VTDR6100_B7.Value));
                        }
                        break;
                    case 24://20阶以下
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R5.Value = VTDR6100_R5.Value - step_h;
                                    else VTDR6100_R5.Value = VTDR6100_R5.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        VTDR6100_R5.Value = VTDR6100_R5.Value - step_l;
                                    else VTDR6100_R5.Value = VTDR6100_R5.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G5.Value = VTDR6100_G5.Value - step_h;
                                    else VTDR6100_G5.Value = VTDR6100_G5.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        VTDR6100_G5.Value = VTDR6100_G5.Value - step_l;
                                    else VTDR6100_G5.Value = VTDR6100_G5.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B5.Value = VTDR6100_B5.Value - step_h;
                                    else VTDR6100_B5.Value = VTDR6100_B5.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        VTDR6100_B5.Value = VTDR6100_B5.Value - step_l;
                                    else VTDR6100_B5.Value = VTDR6100_B5.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            auto_gamma_write(mygamma_r[3], Convert.ToUInt16(VTDR6100_R5.Value), mygamma_g[3], Convert.ToUInt16(VTDR6100_G5.Value), mygamma_b[3], Convert.ToUInt16(VTDR6100_B5.Value));
                        }
                        break;

                }
            }
        }*/


        //private void btnAutoGamma_Click(object sender, EventArgs e)//255阶为例
        //{
        //    int flag = 1;
        //    double Lr_d, Lg_d, Lb_d;
        //    D_lums = new double[30, 3];
        //    D_lum = new double[30];
        //    index = 0;
        //    adjust_Rnum = 0;
        //    adjust_Gnum = 0;
        //    adjust_Bnum = 0;
        //    adjust_l = 0;
        //    adjust_x = 0;
        //    adjust_y = 0;

        //    Button btnTmp = (Button)sender;
        //    switch (btnTmp.Name)
        //    {
        //        case "btnAutogamma":
        //            adjust_class = "btnAutogamma";
        //            break;
        //        case "btnAutogammas":
        //            adjust_class = "btnAutogammas";
        //            break;
        //        default:
        //            break;
        //    }

        //    D_lum[0] = Convert.ToDouble(text195_255.Text);
        //    D_lum[1] = Convert.ToDouble(text195_254.Text);
        //    D_lum[2] = Convert.ToDouble(text195_252.Text);
        //    D_lum[3] = Convert.ToDouble(text195_248.Text);
        //    D_lum[4] = Convert.ToDouble(text195_244.Text);
        //    D_lum[5] = Convert.ToDouble(text195_236.Text);
        //    D_lum[6] = Convert.ToDouble(text195_228.Text);
        //    D_lum[7] = Convert.ToDouble(text195_220.Text);
        //    D_lum[8] = Convert.ToDouble(text195_212.Text);
        //    D_lum[9] = Convert.ToDouble(text195_204.Text);
        //    D_lum[10] = Convert.ToDouble(text195_196.Text);
        //    D_lum[11] = Convert.ToDouble(text195_188.Text);
        //    D_lum[12] = Convert.ToDouble(text195_180.Text);
        //    D_lum[13] = Convert.ToDouble(text195_164.Text);
        //    D_lum[14] = Convert.ToDouble(text195_148.Text);
        //    D_lum[15] = Convert.ToDouble(text195_132.Text);
        //    D_lum[16] = Convert.ToDouble(text195_116.Text);
        //    D_lum[17] = Convert.ToDouble(text195_100.Text);
        //    D_lum[18] = Convert.ToDouble(text195_84.Text);
        //    D_lum[19] = Convert.ToDouble(text195_68.Text);
        //    D_lum[20] = Convert.ToDouble(text195_52.Text);
        //    D_lum[21] = Convert.ToDouble(text195_44.Text);
        //    D_lum[22] = Convert.ToDouble(text195_36.Text);
        //    D_lum[23] = Convert.ToDouble(text195_28.Text);
        //    D_lum[24] = Convert.ToDouble(text195_20.Text);
        //    D_lum[25] = Convert.ToDouble(text195_16.Text);
        //    D_lum[26] = Convert.ToDouble(text195_12.Text);
        //    D_lum[27] = Convert.ToDouble(text195_8.Text);
        //    D_lum[28] = Convert.ToDouble(text195_4.Text);
        //    D_lum[29] = Convert.ToDouble(text195_3.Text);

        //    D_x = Convert.ToDouble(textx.Text);
        //    D_y = Convert.ToDouble(texty.Text);
        //    Lr_d = R_y * ((D_y - G_y) * (B_x - D_x) + (D_x - G_x) * (D_y - B_y)) / B_y / ((D_y - G_y) * (D_x - R_x) + (D_x - G_x) * (R_y - D_y));
        //    Lb_d = 1.0;
        //    Lg_d = G_y * ((D_y - R_y) * (B_x - D_x) + (D_x - R_x) * (D_y - B_y)) / B_y / ((D_y - R_y) * (D_x - G_x) + (D_x - R_x) * (G_y - D_y));

        //    for (int i = 0; i < 30; i++)
        //    {
        //        D_lums[i, 0] = D_lum[i] * Lr_d / (Lr_d + Lg_d + Lb_d);
        //        D_lums[i, 1] = D_lum[i] * Lg_d / (Lr_d + Lg_d + Lb_d);
        //        D_lums[i, 2] = D_lum[i] * Lb_d / (Lr_d + Lg_d + Lb_d);
        //    }

        //    if (MainForm.IC_comboBox.SelectedIndex == 0)//195
        //    {
        //        gamma_r = GAMMAs.RM195_Gamma_r;
        //        gamma_g = GAMMAs.RM195_Gamma_g;
        //        gamma_b = GAMMAs.RM195_Gamma_b;
        //    }
        //    else//295 and 198
        //    {
        //        gamma_r = GAMMAs.RM295_Gamma_r;
        //        gamma_g = GAMMAs.RM295_Gamma_g;
        //        gamma_b = GAMMAs.RM295_Gamma_b;
        //    }

        //    if (adjust_class == "btnAutogammas")
        //    {
        //        txtRM67195Add.Text = "FE";
        //        if (MainForm.IC_comboBox.SelectedIndex == 5)
        //        {
        //            if (RM67198_rbt_HBM.Checked == true)
        //            {
        //                txtRM67195Data.Text = "51";
        //            }
        //            else
        //            {
        //                txtRM67195Data.Text = "50";
        //            }
        //        }
        //        else if (MainForm.IC_comboBox.SelectedIndex == 10)
        //        {
        //            if (RM67198_rbt_HBM.Checked == true)
        //            {
        //                txtRM67195Data.Text = "52";
        //            }
        //            else
        //            {
        //                txtRM67195Data.Text = "50";
        //            }

        //        }

        //        else
        //            txtRM67195Data.Text = "05";
        //        RM196_Others_Click(RM67195_RegW, e);
        //    }
        //    if (adjust_class == "btnAutogamma")
        //    {
        //        string strtmp = null;
        //        FileStream fs;
        //        if (adjust_num == 0 || adjust_num > 5)
        //        {
        //            if (adjust_num > 5)
        //            {
        //                fs = new FileStream("../Base_gamma_195.csv", FileMode.Open, FileAccess.Read);
        //            }
        //            else
        //            {
        //                fs = new FileStream("../Base_gamma_195.csv", FileMode.Open, FileAccess.Read);//Init_gamma_195
        //                adjust_num++;
        //            }
        //            StreamReader streamReader = new StreamReader(fs, Encoding.GetEncoding("GBK"));
        //            streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
        //            string strLine = streamReader.ReadLine();
        //            //循环读取文本信息
        //            while (!string.IsNullOrEmpty(strLine))
        //            {
        //                strtmp = strtmp + strLine + ",";
        //                strLine = streamReader.ReadLine(); //循环读取下一行
        //            }
        //            fs.Close(); //关闭流
        //            streamReader.Close();
        //            string[] arrtmp = strtmp.Split(new Char[] { ',' });
        //            NoRMR0.Text = arrtmp[1].ToString(); NoRMG0.Text = arrtmp[3].ToString(); NoRMB0.Text = arrtmp[5].ToString();
        //            NoRMR3.Text = arrtmp[7].ToString(); NoRMG3.Text = arrtmp[9].ToString(); NoRMB3.Text = arrtmp[11].ToString();
        //            NoRMR4.Text = arrtmp[13].ToString(); NoRMG4.Text = arrtmp[15].ToString(); NoRMB4.Text = arrtmp[17].ToString();
        //            NoRMR8.Text = arrtmp[19].ToString(); NoRMG8.Text = arrtmp[21].ToString(); NoRMB8.Text = arrtmp[23].ToString();
        //            NoRMR12.Text = arrtmp[25].ToString(); NoRMG12.Text = arrtmp[27].ToString(); NoRMB12.Text = arrtmp[29].ToString();
        //            NoRMR16.Text = arrtmp[31].ToString(); NoRMG16.Text = arrtmp[33].ToString(); NoRMB16.Text = arrtmp[35].ToString();
        //            NoRMR20.Text = arrtmp[37].ToString(); NoRMG20.Text = arrtmp[39].ToString(); NoRMB20.Text = arrtmp[41].ToString();
        //            NoRMR28.Text = arrtmp[43].ToString(); NoRMG28.Text = arrtmp[45].ToString(); NoRMB28.Text = arrtmp[47].ToString();
        //            NoRMR36.Text = arrtmp[49].ToString(); NoRMG36.Text = arrtmp[51].ToString(); NoRMB36.Text = arrtmp[53].ToString();
        //            NoRMR44.Text = arrtmp[55].ToString(); NoRMG44.Text = arrtmp[57].ToString(); NoRMB44.Text = arrtmp[59].ToString();
        //            NoRMR52.Text = arrtmp[61].ToString(); NoRMG52.Text = arrtmp[63].ToString(); NoRMB52.Text = arrtmp[65].ToString();
        //            NoRMR68.Text = arrtmp[67].ToString(); NoRMG68.Text = arrtmp[69].ToString(); NoRMB68.Text = arrtmp[71].ToString();
        //            NoRMR84.Text = arrtmp[73].ToString(); NoRMG84.Text = arrtmp[75].ToString(); NoRMB84.Text = arrtmp[77].ToString();
        //            NoRMR100.Text = arrtmp[79].ToString(); NoRMG100.Text = arrtmp[81].ToString(); NoRMB100.Text = arrtmp[83].ToString();
        //            NoRMR116.Text = arrtmp[85].ToString(); NoRMG116.Text = arrtmp[87].ToString(); NoRMB116.Text = arrtmp[89].ToString();
        //            NoRMR132.Text = arrtmp[91].ToString(); NoRMG132.Text = arrtmp[93].ToString(); NoRMB132.Text = arrtmp[95].ToString();
        //            NoRMR148.Text = arrtmp[97].ToString(); NoRMG148.Text = arrtmp[99].ToString(); NoRMB148.Text = arrtmp[101].ToString();
        //            NoRMR164.Text = arrtmp[103].ToString(); NoRMG164.Text = arrtmp[105].ToString(); NoRMB164.Text = arrtmp[107].ToString();
        //            NoRMR180.Text = arrtmp[109].ToString(); NoRMG180.Text = arrtmp[111].ToString(); NoRMB180.Text = arrtmp[113].ToString();
        //            NoRMR188.Text = arrtmp[115].ToString(); NoRMG188.Text = arrtmp[117].ToString(); NoRMB188.Text = arrtmp[119].ToString();
        //            NoRMR196.Text = arrtmp[121].ToString(); NoRMG196.Text = arrtmp[123].ToString(); NoRMB196.Text = arrtmp[125].ToString();
        //            NoRMR204.Text = arrtmp[127].ToString(); NoRMG204.Text = arrtmp[129].ToString(); NoRMB204.Text = arrtmp[131].ToString();
        //            NoRMR212.Text = arrtmp[133].ToString(); NoRMG212.Text = arrtmp[135].ToString(); NoRMB212.Text = arrtmp[137].ToString();
        //            NoRMR220.Text = arrtmp[139].ToString(); NoRMG220.Text = arrtmp[141].ToString(); NoRMB220.Text = arrtmp[143].ToString();
        //            NoRMR228.Text = arrtmp[145].ToString(); NoRMG228.Text = arrtmp[147].ToString(); NoRMB228.Text = arrtmp[149].ToString();
        //            NoRMR236.Text = arrtmp[151].ToString(); NoRMG236.Text = arrtmp[153].ToString(); NoRMB236.Text = arrtmp[155].ToString();
        //            NoRMR244.Text = arrtmp[157].ToString(); NoRMG244.Text = arrtmp[159].ToString(); NoRMB244.Text = arrtmp[161].ToString();
        //            NoRMR248.Text = arrtmp[163].ToString(); NoRMG248.Text = arrtmp[165].ToString(); NoRMB248.Text = arrtmp[167].ToString();
        //            NoRMR252.Text = arrtmp[169].ToString(); NoRMG252.Text = arrtmp[171].ToString(); NoRMB252.Text = arrtmp[173].ToString();
        //            NoRMR254.Text = arrtmp[175].ToString(); NoRMG254.Text = arrtmp[177].ToString(); NoRMB254.Text = arrtmp[179].ToString();
        //            NoRMR255.Text = arrtmp[181].ToString(); NoRMG255.Text = arrtmp[183].ToString(); NoRMB255.Text = arrtmp[185].ToString();

        //            RM67195_GAMMA_Click(RM67195_GammaW_Red, e);//调用寄存器写函数，把255阶R-gamma写入寄存器中。
        //            RM67195_GAMMA_Click(RM67195_GammaW_Green, e);//调用寄存器写函数，把255阶G-gamma写入寄存器中。
        //            RM67195_GAMMA_Click(RM67195_GammaW_Blue, e);//调用寄存器写函数，把255阶B-gamma写入寄存器中。
        //        }
        //        else
        //        {
        //            tmp_gamma_195[3] += Convert.ToInt32(NoRMR3.Value); tmp_gamma_195[4] += Convert.ToInt32(NoRMG3.Value); tmp_gamma_195[5] += Convert.ToInt32(NoRMB3.Value);//把gamma数据都加到临时数组上
        //            tmp_gamma_195[6] += Convert.ToInt32(NoRMR4.Value); tmp_gamma_195[7] += Convert.ToInt32(NoRMG4.Value); tmp_gamma_195[8] += Convert.ToInt32(NoRMB4.Value);
        //            tmp_gamma_195[9] += Convert.ToInt32(NoRMR8.Value); tmp_gamma_195[10] += Convert.ToInt32(NoRMG8.Value); tmp_gamma_195[11] += Convert.ToInt32(NoRMB8.Value);
        //            tmp_gamma_195[12] += Convert.ToInt32(NoRMR12.Value); tmp_gamma_195[13] += Convert.ToInt32(NoRMG12.Value); tmp_gamma_195[14] += Convert.ToInt32(NoRMB12.Value);
        //            tmp_gamma_195[15] += Convert.ToInt32(NoRMR16.Value); tmp_gamma_195[16] += Convert.ToInt32(NoRMG16.Value); tmp_gamma_195[17] += Convert.ToInt32(NoRMB16.Value);
        //            tmp_gamma_195[18] += Convert.ToInt32(NoRMR20.Value); tmp_gamma_195[19] += Convert.ToInt32(NoRMG20.Value); tmp_gamma_195[20] += Convert.ToInt32(NoRMB20.Value);
        //            tmp_gamma_195[21] += Convert.ToInt32(NoRMR28.Value); tmp_gamma_195[22] += Convert.ToInt32(NoRMG28.Value); tmp_gamma_195[23] += Convert.ToInt32(NoRMB28.Value);
        //            tmp_gamma_195[24] += Convert.ToInt32(NoRMR36.Value); tmp_gamma_195[25] += Convert.ToInt32(NoRMG36.Value); tmp_gamma_195[26] += Convert.ToInt32(NoRMB36.Value);
        //            tmp_gamma_195[27] += Convert.ToInt32(NoRMR44.Value); tmp_gamma_195[28] += Convert.ToInt32(NoRMG44.Value); tmp_gamma_195[29] += Convert.ToInt32(NoRMB44.Value);
        //            tmp_gamma_195[30] += Convert.ToInt32(NoRMR52.Value); tmp_gamma_195[31] += Convert.ToInt32(NoRMG52.Value); tmp_gamma_195[32] += Convert.ToInt32(NoRMB52.Value);
        //            tmp_gamma_195[33] += Convert.ToInt32(NoRMR68.Value); tmp_gamma_195[34] += Convert.ToInt32(NoRMG68.Value); tmp_gamma_195[35] += Convert.ToInt32(NoRMB68.Value);
        //            tmp_gamma_195[36] += Convert.ToInt32(NoRMR84.Value); tmp_gamma_195[37] += Convert.ToInt32(NoRMG84.Value); tmp_gamma_195[38] += Convert.ToInt32(NoRMB84.Value);
        //            tmp_gamma_195[39] += Convert.ToInt32(NoRMR100.Value); tmp_gamma_195[40] += Convert.ToInt32(NoRMG100.Value); tmp_gamma_195[41] += Convert.ToInt32(NoRMB100.Value);
        //            tmp_gamma_195[42] += Convert.ToInt32(NoRMR116.Value); tmp_gamma_195[43] += Convert.ToInt32(NoRMG116.Value); tmp_gamma_195[44] += Convert.ToInt32(NoRMB116.Value);
        //            tmp_gamma_195[45] += Convert.ToInt32(NoRMR132.Value); tmp_gamma_195[46] += Convert.ToInt32(NoRMG132.Value); tmp_gamma_195[47] += Convert.ToInt32(NoRMB132.Value);
        //            tmp_gamma_195[48] += Convert.ToInt32(NoRMR148.Value); tmp_gamma_195[49] += Convert.ToInt32(NoRMG148.Value); tmp_gamma_195[50] += Convert.ToInt32(NoRMB148.Value);
        //            tmp_gamma_195[51] += Convert.ToInt32(NoRMR164.Value); tmp_gamma_195[52] += Convert.ToInt32(NoRMG164.Value); tmp_gamma_195[53] += Convert.ToInt32(NoRMB164.Value);
        //            tmp_gamma_195[54] += Convert.ToInt32(NoRMR180.Value); tmp_gamma_195[55] += Convert.ToInt32(NoRMG180.Value); tmp_gamma_195[56] += Convert.ToInt32(NoRMB180.Value);
        //            tmp_gamma_195[57] += Convert.ToInt32(NoRMR188.Value); tmp_gamma_195[58] += Convert.ToInt32(NoRMG188.Value); tmp_gamma_195[59] += Convert.ToInt32(NoRMB188.Value);
        //            tmp_gamma_195[60] += Convert.ToInt32(NoRMR196.Value); tmp_gamma_195[61] += Convert.ToInt32(NoRMG196.Value); tmp_gamma_195[62] += Convert.ToInt32(NoRMB196.Value);
        //            tmp_gamma_195[63] += Convert.ToInt32(NoRMR204.Value); tmp_gamma_195[64] += Convert.ToInt32(NoRMG204.Value); tmp_gamma_195[65] += Convert.ToInt32(NoRMB204.Value);
        //            tmp_gamma_195[66] += Convert.ToInt32(NoRMR212.Value); tmp_gamma_195[67] += Convert.ToInt32(NoRMG212.Value); tmp_gamma_195[68] += Convert.ToInt32(NoRMB212.Value);
        //            tmp_gamma_195[69] += Convert.ToInt32(NoRMR220.Value); tmp_gamma_195[70] += Convert.ToInt32(NoRMG220.Value); tmp_gamma_195[71] += Convert.ToInt32(NoRMB220.Value);
        //            tmp_gamma_195[72] += Convert.ToInt32(NoRMR228.Value); tmp_gamma_195[73] += Convert.ToInt32(NoRMG228.Value); tmp_gamma_195[74] += Convert.ToInt32(NoRMB228.Value);
        //            tmp_gamma_195[75] += Convert.ToInt32(NoRMR236.Value); tmp_gamma_195[76] += Convert.ToInt32(NoRMG236.Value); tmp_gamma_195[77] += Convert.ToInt32(NoRMB236.Value);
        //            tmp_gamma_195[78] += Convert.ToInt32(NoRMR244.Value); tmp_gamma_195[79] += Convert.ToInt32(NoRMG244.Value); tmp_gamma_195[80] += Convert.ToInt32(NoRMB244.Value);
        //            tmp_gamma_195[81] += Convert.ToInt32(NoRMR248.Value); tmp_gamma_195[82] += Convert.ToInt32(NoRMG248.Value); tmp_gamma_195[83] += Convert.ToInt32(NoRMB248.Value);
        //            tmp_gamma_195[84] += Convert.ToInt32(NoRMR252.Value); tmp_gamma_195[85] += Convert.ToInt32(NoRMG252.Value); tmp_gamma_195[86] += Convert.ToInt32(NoRMB252.Value);
        //            tmp_gamma_195[87] += Convert.ToInt32(NoRMR254.Value); tmp_gamma_195[88] += Convert.ToInt32(NoRMG254.Value); tmp_gamma_195[89] += Convert.ToInt32(NoRMB254.Value);
        //            tmp_gamma_195[90] += Convert.ToInt32(NoRMR255.Value); tmp_gamma_195[91] += Convert.ToInt32(NoRMG255.Value); tmp_gamma_195[92] += Convert.ToInt32(NoRMB255.Value);
        //            adjust_num++;

        //            if (adjust_num == 6)
        //            {
        //                NoRMR3.Value = tmp_gamma_195[3] / 5; NoRMG3.Value = tmp_gamma_195[4] / 5; NoRMB3.Value = tmp_gamma_195[5] / 5;
        //                NoRMR4.Value = tmp_gamma_195[6] / 5; NoRMG4.Value = tmp_gamma_195[7] / 5; NoRMB4.Value = tmp_gamma_195[8] / 5;
        //                NoRMR8.Value = tmp_gamma_195[9] / 5; NoRMG8.Value = tmp_gamma_195[10] / 5; NoRMB8.Value = tmp_gamma_195[11] / 5;
        //                NoRMR12.Value = tmp_gamma_195[12] / 5; NoRMG12.Value = tmp_gamma_195[13] / 5; NoRMB12.Value = tmp_gamma_195[14] / 5;
        //                NoRMR16.Value = tmp_gamma_195[15] / 5; NoRMG16.Value = tmp_gamma_195[16] / 5; NoRMB16.Value = tmp_gamma_195[17] / 5;
        //                NoRMR20.Value = tmp_gamma_195[18] / 5; NoRMG20.Value = tmp_gamma_195[19] / 5; NoRMB20.Value = tmp_gamma_195[20] / 5;
        //                NoRMR28.Value = tmp_gamma_195[21] / 5; NoRMG28.Value = tmp_gamma_195[22] / 5; NoRMB28.Value = tmp_gamma_195[23] / 5;
        //                NoRMR36.Value = tmp_gamma_195[24] / 5; NoRMG36.Value = tmp_gamma_195[25] / 5; NoRMB36.Value = tmp_gamma_195[26] / 5;
        //                NoRMR44.Value = tmp_gamma_195[27] / 5; NoRMG44.Value = tmp_gamma_195[28] / 5; NoRMB44.Value = tmp_gamma_195[29] / 5;
        //                NoRMR52.Value = tmp_gamma_195[30] / 5; NoRMG52.Value = tmp_gamma_195[31] / 5; NoRMB52.Value = tmp_gamma_195[32] / 5;
        //                NoRMR68.Value = tmp_gamma_195[33] / 5; NoRMG68.Value = tmp_gamma_195[34] / 5; NoRMB68.Value = tmp_gamma_195[35] / 5;
        //                NoRMR84.Value = tmp_gamma_195[36] / 5; NoRMG84.Value = tmp_gamma_195[37] / 5; NoRMB84.Value = tmp_gamma_195[38] / 5;
        //                NoRMR100.Value = tmp_gamma_195[39] / 5; NoRMG100.Value = tmp_gamma_195[40] / 5; NoRMB100.Value = tmp_gamma_195[41] / 5;
        //                NoRMR116.Value = tmp_gamma_195[42] / 5; NoRMG116.Value = tmp_gamma_195[43] / 5; NoRMB116.Value = tmp_gamma_195[44] / 5;
        //                NoRMR132.Value = tmp_gamma_195[45] / 5; NoRMG132.Value = tmp_gamma_195[46] / 5; NoRMB132.Value = tmp_gamma_195[47] / 5;
        //                NoRMR148.Value = tmp_gamma_195[48] / 5; NoRMG148.Value = tmp_gamma_195[49] / 5; NoRMB148.Value = tmp_gamma_195[50] / 5;
        //                NoRMR164.Value = tmp_gamma_195[51] / 5; NoRMG164.Value = tmp_gamma_195[52] / 5; NoRMB164.Value = tmp_gamma_195[53] / 5;
        //                NoRMR180.Value = tmp_gamma_195[54] / 5; NoRMG180.Value = tmp_gamma_195[55] / 5; NoRMB180.Value = tmp_gamma_195[56] / 5;
        //                NoRMR188.Value = tmp_gamma_195[57] / 5; NoRMG188.Value = tmp_gamma_195[58] / 5; NoRMB188.Value = tmp_gamma_195[59] / 5;
        //                NoRMR196.Value = tmp_gamma_195[60] / 5; NoRMG196.Value = tmp_gamma_195[61] / 5; NoRMB196.Value = tmp_gamma_195[62] / 5;
        //                NoRMR204.Value = tmp_gamma_195[63] / 5; NoRMG204.Value = tmp_gamma_195[64] / 5; NoRMB204.Value = tmp_gamma_195[65] / 5;
        //                NoRMR212.Value = tmp_gamma_195[66] / 5; NoRMG212.Value = tmp_gamma_195[67] / 5; NoRMB212.Value = tmp_gamma_195[68] / 5;
        //                NoRMR220.Value = tmp_gamma_195[69] / 5; NoRMG220.Value = tmp_gamma_195[70] / 5; NoRMB220.Value = tmp_gamma_195[71] / 5;
        //                NoRMR228.Value = tmp_gamma_195[72] / 5; NoRMG228.Value = tmp_gamma_195[73] / 5; NoRMB228.Value = tmp_gamma_195[74] / 5;
        //                NoRMR236.Value = tmp_gamma_195[75] / 5; NoRMG236.Value = tmp_gamma_195[75] / 5; NoRMB236.Value = tmp_gamma_195[77] / 5;
        //                NoRMR244.Value = tmp_gamma_195[78] / 5; NoRMG244.Value = tmp_gamma_195[79] / 5; NoRMB244.Value = tmp_gamma_195[80] / 5;
        //                NoRMR248.Value = tmp_gamma_195[81] / 5; NoRMG248.Value = tmp_gamma_195[82] / 5; NoRMB248.Value = tmp_gamma_195[83] / 5;
        //                NoRMR252.Value = tmp_gamma_195[84] / 5; NoRMG252.Value = tmp_gamma_195[85] / 5; NoRMB252.Value = tmp_gamma_195[86] / 5;
        //                NoRMR254.Value = tmp_gamma_195[87] / 5; NoRMG254.Value = tmp_gamma_195[88] / 5; NoRMB254.Value = tmp_gamma_195[89] / 5;
        //                NoRMR255.Value = tmp_gamma_195[90] / 5; NoRMG255.Value = tmp_gamma_195[91] / 5; NoRMB255.Value = tmp_gamma_195[92] / 5;

        //                fs = new FileStream("../Base_gamma_195.csv", FileMode.OpenOrCreate, FileAccess.Write);
        //                fs.Close();
        //                StreamWriter sw = new StreamWriter(fs.Name, false, Encoding.UTF8);
        //                strtmp = strtmp + "R0," + NoRMR0.Text + "," + "G0," + NoRMG0.Text + "," + "B0," + NoRMB0.Text + "\r\n";
        //                strtmp = strtmp + "R3," + NoRMR3.Text + "," + "G3," + NoRMG3.Text + "," + "B3," + NoRMB3.Text + "\r\n";
        //                strtmp = strtmp + "R4," + NoRMR4.Text + "," + "G4," + NoRMG4.Text + "," + "B4," + NoRMB4.Text + "\r\n";
        //                strtmp = strtmp + "R8," + NoRMR8.Text + "," + "G8," + NoRMG8.Text + "," + "B8," + NoRMB8.Text + "\r\n";
        //                strtmp = strtmp + "R12," + NoRMR12.Text + "," + "G12," + NoRMG12.Text + "," + "B12," + NoRMB12.Text + "\r\n";
        //                strtmp = strtmp + "R16," + NoRMR16.Text + "," + "G16," + NoRMG16.Text + "," + "B16," + NoRMB16.Text + "\r\n";
        //                strtmp = strtmp + "R20," + NoRMR20.Text + "," + "G20," + NoRMG20.Text + "," + "B20," + NoRMB20.Text + "\r\n";
        //                strtmp = strtmp + "R28," + NoRMR28.Text + "," + "G28," + NoRMG28.Text + "," + "B28," + NoRMB28.Text + "\r\n";
        //                strtmp = strtmp + "R36," + NoRMR36.Text + "," + "G36," + NoRMG36.Text + "," + "B36," + NoRMB36.Text + "\r\n";
        //                strtmp = strtmp + "R44," + NoRMR44.Text + "," + "G44," + NoRMG44.Text + "," + "B44," + NoRMB44.Text + "\r\n";
        //                strtmp = strtmp + "R52," + NoRMR52.Text + "," + "G52," + NoRMG52.Text + "," + "B52," + NoRMB52.Text + "\r\n";
        //                strtmp = strtmp + "R68," + NoRMR68.Text + "," + "G68," + NoRMG68.Text + "," + "B68," + NoRMB68.Text + "\r\n";
        //                strtmp = strtmp + "R84," + NoRMR84.Text + "," + "G84," + NoRMG84.Text + "," + "B84," + NoRMB84.Text + "\r\n";
        //                strtmp = strtmp + "R100," + NoRMR100.Text + "," + "G100," + NoRMG100.Text + "," + "B100," + NoRMB100.Text + "\r\n";
        //                strtmp = strtmp + "R116," + NoRMR116.Text + "," + "G116," + NoRMG116.Text + "," + "B116," + NoRMB116.Text + "\r\n";
        //                strtmp = strtmp + "R132," + NoRMR132.Text + "," + "G132," + NoRMG132.Text + "," + "B132," + NoRMB132.Text + "\r\n";
        //                strtmp = strtmp + "R148," + NoRMR148.Text + "," + "G148," + NoRMG148.Text + "," + "B148," + NoRMB148.Text + "\r\n";
        //                strtmp = strtmp + "R164," + NoRMR164.Text + "," + "G164," + NoRMG164.Text + "," + "B164," + NoRMB164.Text + "\r\n";
        //                strtmp = strtmp + "R180," + NoRMR180.Text + "," + "G180," + NoRMG180.Text + "," + "B180," + NoRMB180.Text + "\r\n";
        //                strtmp = strtmp + "R188," + NoRMR188.Text + "," + "G188," + NoRMG188.Text + "," + "B188," + NoRMB188.Text + "\r\n";
        //                strtmp = strtmp + "R196," + NoRMR196.Text + "," + "G196," + NoRMG196.Text + "," + "B196," + NoRMB196.Text + "\r\n";
        //                strtmp = strtmp + "R204," + NoRMR204.Text + "," + "G204," + NoRMG204.Text + "," + "B204," + NoRMB204.Text + "\r\n";
        //                strtmp = strtmp + "R212," + NoRMR212.Text + "," + "G212," + NoRMG212.Text + "," + "B212," + NoRMB212.Text + "\r\n";
        //                strtmp = strtmp + "R220," + NoRMR220.Text + "," + "G220," + NoRMG220.Text + "," + "B220," + NoRMB220.Text + "\r\n";
        //                strtmp = strtmp + "R228," + NoRMR228.Text + "," + "G228," + NoRMG228.Text + "," + "B228," + NoRMB228.Text + "\r\n";
        //                strtmp = strtmp + "R236," + NoRMR236.Text + "," + "G236," + NoRMG236.Text + "," + "B236," + NoRMB236.Text + "\r\n";
        //                strtmp = strtmp + "R244," + NoRMR244.Text + "," + "G244," + NoRMG244.Text + "," + "B244," + NoRMB244.Text + "\r\n";
        //                strtmp = strtmp + "R248," + NoRMR248.Text + "," + "G248," + NoRMG248.Text + "," + "B248," + NoRMB248.Text + "\r\n";
        //                strtmp = strtmp + "R252," + NoRMR252.Text + "," + "G252," + NoRMG252.Text + "," + "B252," + NoRMB252.Text + "\r\n";
        //                strtmp = strtmp + "R254," + NoRMR254.Text + "," + "G254," + NoRMG254.Text + "," + "B254," + NoRMB254.Text + "\r\n";
        //                strtmp = strtmp + "R255," + NoRMR255.Text + "," + "G255," + NoRMG255.Text + "," + "B255," + NoRMB255.Text + "\r\n";
        //                sw.WriteLine(strtmp);
        //                sw.Dispose(); //释放资源
        //                sw.Close(); //关闭数据流        
        //            }
        //        }
        //    }

        //    switch (flag)
        //    {
        //        case 1://寄存器值与亮度正比
        //            {
        //                lum_off = Convert.ToDouble(textlum_off.Text);
        //                x_off = Convert.ToDouble(textx_off.Text);
        //                y_off = Convert.ToDouble(texty_off.Text);
        //                OLED_Show_Click(btnwhite, e);
        //                T5.Enabled = true;
        //            }
        //            break;
        //        case 2://寄存器值与亮度反比
        //            break;
        //        default:
        //            break;
        //    }
        //}
    }
}
